iris/_examples/mvc/grpc-compatible/http-client/main.go
Gerasimos (Makis) Maropoulos b657c5e6af don't fire ErrServerClosed on manually interrupt signals (CTRL/CMD+C)
Former-commit-id: 673c84dd13bb99c0926aa1b4a6b4eff9745403d8
2020-04-28 05:22:58 +03:00

51 lines
992 B
Go

package main
import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/json"
"io/ioutil"
"log"
"net/http"
pb "github.com/kataras/iris/v12/_examples/mvc/grpc-compatible/helloworld"
)
func main() {
b, err := ioutil.ReadFile("../server.crt")
if err != nil {
log.Fatal(err)
}
cp := x509.NewCertPool()
if !cp.AppendCertsFromPEM(b) {
log.Fatal("credentials: failed to append certificates")
}
transport := &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: cp,
},
}
client := http.Client{Transport: transport}
buf := new(bytes.Buffer)
err = json.NewEncoder(buf).Encode(pb.HelloRequest{Name: "world"})
if err != nil {
log.Fatal(err)
}
resp, err := client.Post("https://localhost/helloworld.Greeter/SayHello", "application/json", buf)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
var reply pb.HelloReply
err = json.NewDecoder(resp.Body).Decode(&reply)
if err != nil {
log.Fatal(err)
}
log.Printf("Greeting: %s", reply.GetMessage())
}