1 回答
TA贡献1810条经验 获得超4个赞
看起来我先问了我的问题,然后付出了足够的努力来解决我自己的问题。下面是将 REST 请求与 GRPC 请求一起提供服务的示例
func main() {
lis, err := net.Listen("tcp", ":6789")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
// here we register and HTTP server listening on port 6789
// note that we do this in with gofunc so that the rest of this main function can execute - this probably isn't ideal
http.HandleFunc("/event", Handle)
go http.Serve(lis, nil)
// now we set up GRPC
grpcServer := grpc.NewServer()
// this is a GRPC service defined in a proto file and then generated with protoc
pipelineServer := Server{}
pipeline.RegisterPipelinesServer(grpcServer, pipelineServer)
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("failed to serve: %s", err)
}
}
func Handle(response http.ResponseWriter, request *http.Request) {
log.Infof("handling")
}
如上所述,发送 to 将导致发出日志行。POSTlocalhost:6789/eventhandling
- 1 回答
- 0 关注
- 107 浏览
添加回答
举报