2 Star 0 Fork 338

hxchjm / go-zero

forked from kevwan / go-zero 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gracefulrpc.go 972 Bytes
一键复制 编辑 原始数据 按行查看 历史
kevwan 提交于 2020-09-18 11:41 . rename rpcx to zrpc
package main
import (
"context"
"flag"
"fmt"
"os"
"time"
"github.com/tal-tech/go-zero/core/conf"
"github.com/tal-tech/go-zero/example/graceful/dns/rpc/graceful"
"github.com/tal-tech/go-zero/zrpc"
"google.golang.org/grpc"
)
var configFile = flag.String("f", "etc/config.json", "the config file")
type GracefulServer struct{}
func NewGracefulServer() *GracefulServer {
return &GracefulServer{}
}
func (gs *GracefulServer) Grace(ctx context.Context, req *graceful.Request) (*graceful.Response, error) {
fmt.Println("=>", req)
time.Sleep(time.Millisecond * 10)
hostname, err := os.Hostname()
if err != nil {
return nil, err
}
return &graceful.Response{
Host: hostname,
}, nil
}
func main() {
flag.Parse()
var c zrpc.RpcServerConf
conf.MustLoad(*configFile, &c)
server := zrpc.MustNewServer(c, func(grpcServer *grpc.Server) {
graceful.RegisterGraceServiceServer(grpcServer, NewGracefulServer())
})
defer server.Stop()
server.Start()
}
Go
1
https://gitee.com/hxchjm/go-zero.git
git@gitee.com:hxchjm/go-zero.git
hxchjm
go-zero
go-zero
3eb88c4e4bf1

搜索帮助