perm.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "perms-system-server/internal/config"
  6. "perms-system-server/internal/handler"
  7. "perms-system-server/internal/response"
  8. "perms-system-server/internal/server"
  9. "perms-system-server/internal/svc"
  10. "perms-system-server/pb"
  11. "github.com/zeromicro/go-zero/core/conf"
  12. "github.com/zeromicro/go-zero/rest"
  13. "github.com/zeromicro/go-zero/zrpc"
  14. "google.golang.org/grpc"
  15. "google.golang.org/grpc/reflection"
  16. )
  17. var configFile = flag.String("f", "etc/perm-api.yaml", "the config file")
  18. func main() {
  19. flag.Parse()
  20. var c config.Config
  21. conf.MustLoad(*configFile, &c)
  22. response.Setup()
  23. svcCtx := svc.NewServiceContext(c)
  24. httpServer := rest.MustNewServer(c.RestConf)
  25. defer httpServer.Stop()
  26. handler.RegisterHandlers(httpServer, svcCtx)
  27. rpcServer := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
  28. pb.RegisterPermServiceServer(grpcServer, server.NewPermServer(svcCtx))
  29. if c.Mode == "dev" {
  30. reflection.Register(grpcServer)
  31. }
  32. })
  33. defer rpcServer.Stop()
  34. go func() {
  35. fmt.Printf("Starting gRPC server at %s...\n", c.RpcServerConf.ListenOn)
  36. rpcServer.Start()
  37. }()
  38. fmt.Printf("Starting HTTP server at %s:%d...\n", c.Host, c.Port)
  39. httpServer.Start()
  40. }