fusenapi/goctl_template/rpc/main.tpl

39 lines
897 B
Smarty
Raw Normal View History

2023-06-05 09:56:55 +00:00
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()
var c config.Config
2023-09-19 09:34:10 +00:00
fsconfig.StartNacosConfig(*configFile, &c, nil)
2023-09-19 03:41:38 +00:00
2023-07-12 02:22:03 +00:00
c.Timeout = int64(time.Second * 15)
2023-06-05 09:56:55 +00:00
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()
}