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. go func() {
  25. rpcServer := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
  26. pb.RegisterPermServiceServer(grpcServer, server.NewPermServer(svcCtx))
  27. reflection.Register(grpcServer)
  28. })
  29. defer rpcServer.Stop()
  30. fmt.Printf("Starting gRPC server at %s...\n", c.RpcServerConf.ListenOn)
  31. rpcServer.Start()
  32. }()
  33. httpServer := rest.MustNewServer(c.RestConf)
  34. defer httpServer.Stop()
  35. handler.RegisterHandlers(httpServer, svcCtx)
  36. fmt.Printf("Starting HTTP server at %s:%d...\n", c.Host, c.Port)
  37. httpServer.Start()
  38. }