package rpcx import ( "context" "encoding/json" "fmt" "git.wanpinghui.com/WPH/go_common/wph" "git.wanpinghui.com/WPH/go_common/wph/date" "github.com/smallnest/rpcx/client" ) type DemoRQ struct { ID wph.Long `json:"id"` } type DemoRES struct { ID wph.Long `json:"id"` StartTime date.Time `json:"startTime"` } func main() { ctx := context.Background() rpcRQ := &DemoRQ{ID: wph.NextId()} rpcRES := &DemoRES{} c := client.NewClient(client.DefaultOption) err := c.Connect("tcp", "localhost:10000") //err := c.Connect("tcp", "api.88ba.com:10007") if err != nil { fmt.Printf("failed to connect: %v", err) return } defer c.Close() //token := "rpc bearer cdEger5i9943rFqewg" //metadata := ctx.Value(share.ReqMetaDataKey) //if metadata == nil { // metadata = map[string]string{} // ctx = context.WithValue(ctx, share.ReqMetaDataKey, metadata) //} //m := metadata.(map[string]string) //m[share.AuthKey] = token println(1) err = c.Call(ctx, "DemoService", "TestFn", rpcRQ, rpcRES) println(2) //d := client.NewPeer2PeerDiscovery("tcp@wph-micro-auth:10007", "") //c := client.NewXClient("GovAuth", client.Failtry, client.RandomSelect, d, client.DefaultOption) //c.Auth(token) //err := c.Call(context.Background(), "CheckUser", rpcRQ, rpcRES) if err != nil { fmt.Printf("rpc client call err=%s\n", err.Error()) err = nil } else { b, _ := json.Marshal(rpcRES) println("result is ", string(b)) } }