github.com/micro/go-micro/examples@v0.0.0-20210105173217-bf4ab679e18b/greeter/cli/sidecar/sidecar.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "fmt" 6 "io/ioutil" 7 "net/http" 8 9 "github.com/golang/protobuf/proto" 10 hello "github.com/micro/go-micro/examples/greeter/srv/proto/hello" 11 ) 12 13 func main() { 14 req, err := proto.Marshal(&hello.Request{Name: "John"}) 15 if err != nil { 16 fmt.Println(err) 17 return 18 } 19 20 r, err := http.Post("http://localhost:8081/greeter/say/hello", "application/protobuf", bytes.NewReader(req)) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 defer r.Body.Close() 26 27 b, err := ioutil.ReadAll(r.Body) 28 if err != nil { 29 fmt.Println(err) 30 return 31 } 32 rsp := &hello.Response{} 33 if err := proto.Unmarshal(b, rsp); err != nil { 34 fmt.Println(err) 35 return 36 } 37 fmt.Println(rsp.Msg) 38 }