Mikaelemmmm / go-zero-looklook

🔥基于go-zero(go zero) 微服务全技术栈开发最佳实践项目。Develop best practice projects based on the full technology stack of go zero (go zero) microservices.
https://go-zero.dev
MIT License
4.43k stars 826 forks source link

deploy下的goctl模板handler.tpl在goctl的1.5.3有问题 #119

Closed PittYao closed 1 year ago

PittYao commented 1 year ago
  1. windows下执行 image

  2. image 3.执行 goctl api go -api usercenter.api -dir ../ 4.报错 image

修改: 1.将 {{if .After1_1_10}}"github.com/zeromicro/go-zero/rest/httpx"{{end}} 修改为 "github.com/zeromicro/go-zero/rest/httpx"

PittYao commented 1 year ago

rpc生成报错 goctl rpc protoc usercenter.proto --go_out=../ --go-grpc_out=../ --zrpc_out=../ --style=goZero image

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()
}
Mikaelemmmm commented 1 year ago

rpc生成报错 goctl rpc protoc usercenter.proto --go_out=../ --go-grpc_out=../ --zrpc_out=../ --style=goZero image

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