Closed PittYao closed 1 year ago
rpc生成报错
goctl rpc protoc usercenter.proto --go_out=../ --go-grpc_out=../ --zrpc_out=../ --style=goZero
rpc/main.tpl更新 由
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
svr := server.New{{.serviceNew}}Server(ctx)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
{{.pkg}}.Register{{.service}}Server(grpcServer, svr)
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
//rpc log
s.AddUnaryInterceptors(rpcserver.LoggerInterceptor)
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}
改为
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
{{range .serviceNames}} {{.Pkg}}.Register{{.Service}}Server(grpcServer, {{.ServerPkg}}.New{{.Service}}Server(ctx))
{{end}}
if c.Mode == service.DevMode || c.Mode == service.TestMode {
reflection.Register(grpcServer)
}
})
//rpc log
s.AddUnaryInterceptors(rpcserver.LoggerInterceptor)
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}
rpc生成报错
goctl rpc protoc usercenter.proto --go_out=../ --go-grpc_out=../ --zrpc_out=../ --style=goZero
rpc/main.tpl更新 由
func main() { flag.Parse() var c config.Config conf.MustLoad(*configFile, &c) ctx := svc.NewServiceContext(c) svr := server.New{{.serviceNew}}Server(ctx) s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { {{.pkg}}.Register{{.service}}Server(grpcServer, svr) if c.Mode == service.DevMode || c.Mode == service.TestMode { reflection.Register(grpcServer) } }) //rpc log s.AddUnaryInterceptors(rpcserver.LoggerInterceptor) defer s.Stop() fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) s.Start() }
改为
func main() { flag.Parse() var c config.Config conf.MustLoad(*configFile, &c) ctx := svc.NewServiceContext(c) s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { {{range .serviceNames}} {{.Pkg}}.Register{{.Service}}Server(grpcServer, {{.ServerPkg}}.New{{.Service}}Server(ctx)) {{end}} if c.Mode == service.DevMode || c.Mode == service.TestMode { reflection.Register(grpcServer) } }) //rpc log s.AddUnaryInterceptors(rpcserver.LoggerInterceptor) defer s.Stop() fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) s.Start() }
可以提个pr
windows下执行
3.执行
goctl api go -api usercenter.api -dir ../
4.报错修改: 1.将
{{if .After1_1_10}}"github.com/zeromicro/go-zero/rest/httpx"{{end}}
修改为"github.com/zeromicro/go-zero/rest/httpx"