proto/goutils/proto_build/tpls/main.tpl
huangsimin@fusen.cn c0cbff775f 最新版本
2023-11-27 17:36:02 +08:00

41 lines
935 B
Smarty

package main
import (
"fmt"
"net"
"fusen-basic/env"
"fusen-basic/utils/log"
"{{.ProjectName}}/gen/go/service"
"{{.ProjectName}}/server/config"
{{range .LogicDirNames}}
"{{$.ProjectName}}/{{.}}"
{{- end}}
"google.golang.org/grpc"
)
func main() {
fusen := env.NewFusen[config.Config]()
fusen.StartNacos(nil)
service.AutoGrpcInit(fusen)
sopt := grpc.UnaryInterceptor(fusen.Interceptor())
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", fusen.ServiceConfig.Port)) //
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer(sopt) //grpc服务
{{range .StructServiceNames}}
service.Register{{.StructServiceName}}Server(s, &{{.LogicPackageName}}.{{.StructServiceName}}LogicGrpc{}) // {{.LogicPackageName}}
{{- end}}
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}