1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-05-19 21:23:04 +02:00
Benjamin 5d5aee1f08
replace ioutil with io and os (#2327)
set the go version to 1.16 in pr.yml and tests.yml, so as to be consistent with the version in go.mod.
2021-10-30 19:24:40 +01:00

39 lines
676 B
Go

package main
import (
"bytes"
"fmt"
"io"
"net/http"
"github.com/golang/protobuf/proto"
hello "github.com/asim/go-micro/examples/v4/greeter/srv/proto/hello"
)
func main() {
req, err := proto.Marshal(&hello.Request{Name: "John"})
if err != nil {
fmt.Println(err)
return
}
r, err := http.Post("http://localhost:8081/greeter/say/hello", "application/protobuf", bytes.NewReader(req))
if err != nil {
fmt.Println(err)
return
}
defer r.Body.Close()
b, err := io.ReadAll(r.Body)
if err != nil {
fmt.Println(err)
return
}
rsp := &hello.Response{}
if err := proto.Unmarshal(b, rsp); err != nil {
fmt.Println(err)
return
}
fmt.Println(rsp.Msg)
}