main.go 578 B

12345678910111213141516171819202122232425
  1. package main
  2. import (
  3. "../service"
  4. "context"
  5. client2 "github.com/smallnest/rpcx/client"
  6. "log"
  7. )
  8. const ADDRESS string = "tcp@localhost:10001"
  9. func main() {
  10. d := client2.NewPeer2PeerDiscovery(ADDRESS, "")
  11. c := client2.NewXClient("Format", client2.Failtry, client2.RandomSelect, d, client2.DefaultOption)
  12. defer func(c client2.XClient) {
  13. _ = c.Close()
  14. }(c)
  15. replay := &service.Replay{}
  16. err := c.Call(context.Background(), "DoFormat", &service.Args{Text: "Hello world!"}, replay)
  17. if err != nil {
  18. log.Fatalf("failed to call: %v", err)
  19. }
  20. log.Println(replay.Text)
  21. }