perm.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. reflection.Register(grpcServer)
  30. })
  31. defer rpcServer.Stop()
  32. go func() {
  33. fmt.Printf("Starting gRPC server at %s...\n", c.RpcServerConf.ListenOn)
  34. rpcServer.Start()
  35. }()
  36. fmt.Printf("Starting HTTP server at %s:%d...\n", c.Host, c.Port)
  37. httpServer.Start()
  38. }