| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package main
- import (
- "flag"
- "fmt"
- "perms-system-server/internal/config"
- "perms-system-server/internal/handler"
- "perms-system-server/internal/response"
- "perms-system-server/internal/server"
- "perms-system-server/internal/svc"
- "perms-system-server/pb"
- "github.com/zeromicro/go-zero/core/conf"
- "github.com/zeromicro/go-zero/rest"
- "github.com/zeromicro/go-zero/zrpc"
- "google.golang.org/grpc"
- "google.golang.org/grpc/reflection"
- )
- var configFile = flag.String("f", "etc/perm-api.yaml", "the config file")
- func main() {
- flag.Parse()
- var c config.Config
- conf.MustLoad(*configFile, &c)
- response.Setup()
- svcCtx := svc.NewServiceContext(c)
- httpServer := rest.MustNewServer(c.RestConf)
- defer httpServer.Stop()
- handler.RegisterHandlers(httpServer, svcCtx)
- rpcServer := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
- pb.RegisterPermServiceServer(grpcServer, server.NewPermServer(svcCtx))
- if c.Mode == "dev" {
- reflection.Register(grpcServer)
- }
- })
- defer rpcServer.Stop()
- go func() {
- fmt.Printf("Starting gRPC server at %s...\n", c.RpcServerConf.ListenOn)
- rpcServer.Start()
- }()
- fmt.Printf("Starting HTTP server at %s:%d...\n", c.Host, c.Port)
- httpServer.Start()
- }
|