go-zero/example/graceful/etcd/api/graceful.go

33 lines
709 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package main
import (
"flag"
2020-08-08 16:40:10 +08:00
"github.com/tal-tech/go-zero/core/conf"
"github.com/tal-tech/go-zero/example/graceful/etcd/api/config"
"github.com/tal-tech/go-zero/example/graceful/etcd/api/handler"
"github.com/tal-tech/go-zero/example/graceful/etcd/api/svc"
"github.com/tal-tech/go-zero/rest"
2020-09-18 11:41:52 +08:00
"github.com/tal-tech/go-zero/zrpc"
2020-07-26 17:09:05 +08:00
)
var configFile = flag.String("f", "etc/graceful-api.json", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
2020-09-18 11:41:52 +08:00
client := zrpc.MustNewClient(c.Rpc)
2020-07-26 17:09:05 +08:00
ctx := &svc.ServiceContext{
Client: client,
}
2020-07-31 11:45:16 +08:00
engine := rest.MustNewServer(c.RestConf)
2020-07-26 17:09:05 +08:00
defer engine.Stop()
handler.RegisterHandlers(engine, ctx)
engine.Start()
}