graceful.go 703 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "flag"
  4. "github.com/tal-tech/go-zero/core/conf"
  5. "github.com/tal-tech/go-zero/rest"
  6. "github.com/tal-tech/go-zero/zrpc"
  7. "github.com/zeromicro/zero-examples/graceful/dns/api/config"
  8. "github.com/zeromicro/zero-examples/graceful/dns/api/handler"
  9. "github.com/zeromicro/zero-examples/graceful/dns/api/svc"
  10. )
  11. var configFile = flag.String("f", "etc/graceful-api.json", "the config file")
  12. func main() {
  13. flag.Parse()
  14. var c config.Config
  15. conf.MustLoad(*configFile, &c)
  16. client := zrpc.MustNewClient(c.Rpc)
  17. ctx := &svc.ServiceContext{
  18. Client: client,
  19. }
  20. engine := rest.MustNewServer(c.RestConf)
  21. defer engine.Stop()
  22. handler.RegisterHandlers(engine, ctx)
  23. engine.Start()
  24. }