tianyuan-api-server/apps/user/user.go
2024-10-02 00:57:17 +08:00

44 lines
1.2 KiB
Go

package main
import (
"flag"
"fmt"
"tianyuan-api/apps/user/internal/config"
authServer "tianyuan-api/apps/user/internal/server/auth"
enterpriseServer "tianyuan-api/apps/user/internal/server/enterprise"
userServer "tianyuan-api/apps/user/internal/server/user"
"tianyuan-api/apps/user/internal/svc"
"tianyuan-api/apps/user/user"
"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/user.yaml", "the config file")
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) {
user.RegisterEnterpriseServer(grpcServer, enterpriseServer.NewEnterpriseServer(ctx))
user.RegisterAuthServer(grpcServer, authServer.NewAuthServer(ctx))
user.RegisterUserServer(grpcServer, userServer.NewUserServer(ctx))
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()
}