consul-demo/sample/sample-service.go

27 lines
418 B
Go
Raw Permalink Normal View History

2021-01-22 14:50:57 +00:00
package sample
import (
"context"
2021-01-23 13:58:32 +00:00
"strconv"
"time"
2021-01-22 14:50:57 +00:00
pb "myschools.me/suguo/consul-demo/proto"
)
//Server 微服务
type Server struct {
}
2021-01-23 13:58:32 +00:00
var r int
2021-01-22 14:50:57 +00:00
//Say 实现微服务接口
func (s *Server) Say(c context.Context, req *pb.SayRequest) (*pb.SayResponse, error) {
2021-01-23 13:58:32 +00:00
if r == 0 {
r = int(time.Now().Unix())
}
2021-01-22 14:50:57 +00:00
resp := &pb.SayResponse{
2021-01-23 13:58:32 +00:00
Reply: req.Name + req.Day + " " + strconv.Itoa(r),
2021-01-22 14:50:57 +00:00
}
return resp, nil
}