示例#1
0
func main() {
	go grpcServer()
	conn, err := grpc.Dial("localhost:8675", grpc.WithInsecure())
	if err != nil {
		glog.Fatal(err)
	}

	cli := foo.NewFooServiceClient(conn)

	mux, err := foo.MakeMux_FooService(cli, noMiddleware, jsonEncoder)
	if err != nil {
		glog.Fatal(err)
	}

	http.ListenAndServe("localhost:8000", mux)
}
示例#2
0
func main() {
	go grpcServer()
	ctx := context.Background()

	conn, err := grpc.Dial("localhost:8675", grpc.WithInsecure())
	if err != nil {
		glog.Fatal(err)
	}

	cli := foo.NewFooServiceClient(conn)

	http.ListenAndServe("localhost:8000", foo.MakeMux_FooService(cli, kithttp.Server{
		Context: ctx,
		Logger:  log.NewLogfmtLogger(os.Stderr),
		EncodeResponseFunc: func(wr http.ResponseWriter, data interface{}) error {
			return json.NewEncoder(wr).Encode(data)
		},
	}))
}