1234567891011121314151617181920212223242526272829303132333435 |
- package main
- import (
- "context"
- "fmt"
- "git.nspix.com/golang/micro/gateway/rpc"
- "time"
- )
- type (
- mathRequest struct {
- NumA int `json:"num_a"`
- NumB int `json:"num_b"`
- }
- mathResponse struct {
- Value int `json:"value"`
- }
- )
- func main() {
- c := rpc.NewClient()
- if err := c.Dialer("tcp", "127.0.0.1:52743"); err != nil {
- panic(err)
- }
- defer c.Close()
- ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
- if res, err := c.Do(ctx, rpc.NewRequest("math.add", &mathRequest{NumA: 100, NumB: 12})); err == nil {
- var i mathResponse
- fmt.Println(res.Decode(&i))
- fmt.Println(i)
- } else {
- fmt.Println(err)
- }
- }
|