graceful.go 709 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/example/graceful/etcd/api/config"
  6. "github.com/tal-tech/go-zero/example/graceful/etcd/api/handler"
  7. "github.com/tal-tech/go-zero/example/graceful/etcd/api/svc"
  8. "github.com/tal-tech/go-zero/rest"
  9. "github.com/tal-tech/go-zero/zrpc"
  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. }