fusenapi/goctl_template_backend/rpc/main.tpl
2023-09-19 11:41:38 +08:00

40 lines
958 B
Smarty

package main
import (
"flag"
"fmt"
{{.imports}}
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
var configFile = flag.String("f", "etc/{{.serviceName}}.yaml", "the config file")
func main() {
flag.Parse()
cfgContent := fsconfig.StartNacosConfig(configFile,nil)
var c config.Config
conf.LoadConfigFromYamlBytes([]byte(cfgContent),&c)
c.Timeout = int64(time.Second * 15)
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)
}
})
defer s.Stop()
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
s.Start()
}