hello.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/wuntsong-org/go-zero-plus/tools/goctlwt/example/rpc/hello/internal/config"
  6. greetServer "github.com/wuntsong-org/go-zero-plus/tools/goctlwt/example/rpc/hello/internal/server/greet"
  7. "github.com/wuntsong-org/go-zero-plus/tools/goctlwt/example/rpc/hello/internal/svc"
  8. "github.com/wuntsong-org/go-zero-plus/tools/goctlwt/example/rpc/hello/pb/hello"
  9. "github.com/wuntsong-org/go-zero-plus/core/conf"
  10. "github.com/wuntsong-org/go-zero-plus/core/service"
  11. "github.com/wuntsong-org/go-zero-plus/zrpc"
  12. "google.golang.org/grpc"
  13. "google.golang.org/grpc/reflection"
  14. )
  15. var configFile = flag.String("f", "etc/hello.yaml", "the config file")
  16. func main() {
  17. flag.Parse()
  18. var c config.Config
  19. conf.MustLoad(*configFile, &c)
  20. ctx := svc.NewServiceContext(c)
  21. s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
  22. hello.RegisterGreetServer(grpcServer, greetServer.NewGreetServer(ctx))
  23. if c.Mode == service.DevMode || c.Mode == service.TestMode {
  24. reflection.Register(grpcServer)
  25. }
  26. })
  27. defer s.Stop()
  28. fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
  29. s.Start()
  30. }