1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-04-11 11:02:02 +02:00

39 lines
685 B
Go
Raw Normal View History

2020-12-26 15:17:20 +00:00
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"github.com/golang/protobuf/proto"
2020-12-26 15:21:29 +00:00
hello "github.com/micro/go-micro/examples/greeter/srv/proto/hello"
2020-12-26 15:17:20 +00:00
)
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 := ioutil.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)
}