tianyuan-api-server/apps/user/user.go
2024-10-12 20:41:55 +08:00

63 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"flag"
"fmt"
"os"
"tianyuan-api/apps/user/internal/config"
apirequestserviceServer "tianyuan-api/apps/user/internal/server/apirequestservice"
authServer "tianyuan-api/apps/user/internal/server/auth"
enterpriseServer "tianyuan-api/apps/user/internal/server/enterprise"
userServer "tianyuan-api/apps/user/internal/server/user"
walletserviceServer "tianyuan-api/apps/user/internal/server/walletservice"
"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"
)
func main() {
// 读取环境变量 ENV默认为 "prod"
env := os.Getenv("ENV")
if env == "" {
env = "production"
}
// 根据 ENV 加载不同的配置文件
var defaultConfigFile string
if env == "development" {
defaultConfigFile = "etc/user.dev.yaml" // 开发环境配置
} else {
defaultConfigFile = "etc/user.yaml" // 生产环境配置
}
// 允许通过命令行参数覆盖配置文件路径
configFile := flag.String("f", defaultConfigFile, "the config file")
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))
user.RegisterWalletServiceServer(grpcServer, walletserviceServer.NewWalletServiceServer(ctx))
user.RegisterApiRequestServiceServer(grpcServer, apirequestserviceServer.NewApiRequestServiceServer(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()
}