1 Star 0 Fork 0

clearluo/gotools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server.go 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
clearluo 提交于 2022-02-18 14:10 . modify
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
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/clearluo/gotools.git
git@gitee.com:clearluo/gotools.git
clearluo
gotools
gotools
v1.2.9

搜索帮助

0d507c66 1850385 C8b1a773 1850385