代码拉取完成,页面将自动刷新
package main
import (
"context"
"net"
"time"
"gitee.com/clearluo/gotools/net/rpcclient/grpcTest/proto"
"gitee.com/clearluo/gotools/zaplog"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc"
)
const (
Address string = ":18100"
Network string = "tcp"
)
type SimpleService struct{}
func (s *SimpleService) GetSimpleInfo(ctx context.Context, req *proto.SimpleRequest) (*proto.SimpleResponse, error) {
zaplog.Infof("get from client:%v by:%v", req.Data, req.Num)
resp := &proto.SimpleResponse{
Code: req.Num,
Value: "gRPC",
}
if req.Num%2 == 0 {
time.Sleep(time.Second)
}
return resp, nil
}
func main() {
listener, err := net.Listen(Network, Address)
if err != nil {
zaplog.Infof("net.listen err:%v", err)
return
}
zaplog.Infof(Address + " net listening...")
creds, err := credentials.NewServerTLSFromFile("grpcTest/cert/server.crt", "grpcTest/cert/server.key")
if err != nil {
zaplog.Infof("Failed to generate credentials %v", err)
return
}
grpcServer := grpc.NewServer(grpc.Creds(creds))
proto.RegisterSimpleServer(grpcServer, &SimpleService{})
if err := grpcServer.Serve(listener); err != nil {
zaplog.Infof("grpcTest server err:%v", err)
return
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。