注册consul及DeRegister测试通过

This commit is contained in:
suguo.yao 2021-01-23 14:33:41 +08:00
parent 5c94031de2
commit 0ac3f91efa
7 changed files with 115 additions and 754 deletions

View File

@ -19,8 +19,8 @@ func Register(id string, name string, port int, tags ...string) {
client, err := consulapi.NewClient(config)
if err != nil {
log.WithFields(log.Fields{
"func": "NewClient",
}).Errorf("%v", err)
"func": "Register",
}).Errorf("NewClient: %v", err)
return
}
@ -30,7 +30,7 @@ func Register(id string, name string, port int, tags ...string) {
registration.Name = name
registration.Port = port
registration.Tags = tags
registration.Address = "0.0.0.0"
registration.Address = "192.168.8.146"
// 增加consul健康检查回调函数
check := new(consulapi.AgentServiceCheck)
@ -43,22 +43,24 @@ func Register(id string, name string, port int, tags ...string) {
// 注册服务到consul
if err := client.Agent().ServiceRegister(registration); err != nil {
log.WithFields(log.Fields{
"func": "ServiceRegister",
}).Errorf("%v", err)
"func": "Register",
}).Errorf("ServiceRegister: %v", err)
}
}
//DeRegister 取消consul注册的服务
func DeRegister() {
func DeRegister(name string) {
// 创建连接consul服务配置
config := consulapi.DefaultConfig()
config.Address = "127.0.0.1:8500"
config.Address = consulAddr
client, err := consulapi.NewClient(config)
if err != nil {
log.Fatal("consul client error : ", err)
log.WithFields(log.Fields{
"func": "DeRegister",
}).Errorf("%v", err)
}
client.Agent().ServiceDeregister("111")
client.Agent().ServiceDeregister(name)
}
//FindServer 从consul中发现服务

35
health/health-service.go Normal file
View File

@ -0,0 +1,35 @@
package health
import (
"context"
log "github.com/sirupsen/logrus"
pb "myschools.me/suguo/consul-demo/proto"
)
//Server 微服务
type Server struct {
}
//Check 实现微服务接口
func (s *Server) Check(c context.Context, req *pb.HealthCheckRequest) (*pb.HealthCheckResponse, error) {
log.WithFields(log.Fields{
"func": "Check",
}).Infof("%s %s", req.Service, req.GetService())
resp := &pb.HealthCheckResponse{
Status: pb.HealthCheckResponse_SERVING,
}
return resp, nil
}
//Watch 实现微服务接口stream
func (s *Server) Watch(req *pb.HealthCheckRequest, out pb.Health_WatchServer) error {
log.WithFields(log.Fields{
"func": "Watch",
}).Infof("%s", req.GetService())
out.Send(&pb.HealthCheckResponse{
Status: pb.HealthCheckResponse_SERVING,
})
return nil
}

1
logs/demo Symbolic link
View File

@ -0,0 +1 @@
demo2021012314.log

61
logs/demo2021012314.log Normal file
View File

@ -0,0 +1,61 @@
time="2021-01-23T14:25:44+08:00" level=error msg="ServiceRegister: Unexpected response code: 400 (Invalid service address)" func=Register
time="2021-01-23T14:27:16+08:00" level=info func=Check
time="2021-01-23T14:27:21+08:00" level=info func=Check
time="2021-01-23T14:27:26+08:00" level=info func=Check
time="2021-01-23T14:27:31+08:00" level=info func=Check
time="2021-01-23T14:27:36+08:00" level=info func=Check
time="2021-01-23T14:27:41+08:00" level=info func=Check
time="2021-01-23T14:27:57+08:00" level=info func=Check
time="2021-01-23T14:28:02+08:00" level=info func=Check
time="2021-01-23T14:28:07+08:00" level=info func=Check
time="2021-01-23T14:28:12+08:00" level=info func=Check
time="2021-01-23T14:28:17+08:00" level=info func=Check
time="2021-01-23T14:28:22+08:00" level=info func=Check
time="2021-01-23T14:28:27+08:00" level=info func=Check
time="2021-01-23T14:28:32+08:00" level=info func=Check
time="2021-01-23T14:28:37+08:00" level=info func=Check
time="2021-01-23T14:28:42+08:00" level=info func=Check
time="2021-01-23T14:28:47+08:00" level=info func=Check
time="2021-01-23T14:28:52+08:00" level=info func=Check
time="2021-01-23T14:28:57+08:00" level=info func=Check
time="2021-01-23T14:29:02+08:00" level=info func=Check
time="2021-01-23T14:29:07+08:00" level=info func=Check
time="2021-01-23T14:29:12+08:00" level=info func=Check
time="2021-01-23T14:29:17+08:00" level=info func=Check
time="2021-01-23T14:29:22+08:00" level=info func=Check
time="2021-01-23T14:29:27+08:00" level=info func=Check
time="2021-01-23T14:29:32+08:00" level=info func=Check
time="2021-01-23T14:29:37+08:00" level=info func=Check
time="2021-01-23T14:29:56+08:00" level=info func=Check
time="2021-01-23T14:30:01+08:00" level=info func=Check
time="2021-01-23T14:30:06+08:00" level=info func=Check
time="2021-01-23T14:30:11+08:00" level=info func=Check
time="2021-01-23T14:30:16+08:00" level=info func=Check
time="2021-01-23T14:30:21+08:00" level=info func=Check
time="2021-01-23T14:30:26+08:00" level=info func=Check
time="2021-01-23T14:30:31+08:00" level=info func=Check
time="2021-01-23T14:30:36+08:00" level=info func=Check
time="2021-01-23T14:30:41+08:00" level=info func=Check
time="2021-01-23T14:30:46+08:00" level=info func=Check
time="2021-01-23T14:30:51+08:00" level=info func=Check
time="2021-01-23T14:31:41+08:00" level=info msg=" " func=Check
time="2021-01-23T14:31:46+08:00" level=info msg=" " func=Check
time="2021-01-23T14:31:51+08:00" level=info msg=" " func=Check
time="2021-01-23T14:31:56+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:02+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:07+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:12+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:17+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:22+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:27+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:32+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:37+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:42+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:47+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:52+08:00" level=info msg=" " func=Check
time="2021-01-23T14:32:57+08:00" level=info msg=" " func=Check
time="2021-01-23T14:33:02+08:00" level=info msg=" " func=Check
time="2021-01-23T14:33:07+08:00" level=info msg=" " func=Check
time="2021-01-23T14:33:12+08:00" level=info msg=" " func=Check
time="2021-01-23T14:33:17+08:00" level=info msg=" " func=Check
time="2021-01-23T14:33:22+08:00" level=info msg=" " func=Check

View File

@ -9,6 +9,8 @@ import (
"time"
"google.golang.org/grpc"
"myschools.me/suguo/consul-demo/consul"
"myschools.me/suguo/consul-demo/health"
pb "myschools.me/suguo/consul-demo/proto"
"myschools.me/suguo/consul-demo/sample"
)
@ -26,6 +28,7 @@ func main() {
// grpc服务定义
s := grpc.NewServer()
pb.RegisterHelloServer(s, &sample.Server{})
pb.RegisterHealthServer(s, &health.Server{})
// grpc服务启动
go func() {
@ -40,6 +43,10 @@ func main() {
}
}()
//注册至consul
consul.Register(APPNAME, APPNAME, 9001, "demo")
defer consul.DeRegister(APPNAME)
// 服务停止相应
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)

View File

@ -1,438 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.25.0
// protoc v3.11.4
// source: proto/health.proto
package grpc_health_v1
import (
context "context"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type HealthCheckResponse_ServingStatus int32
const (
HealthCheckResponse_UNKNOWN HealthCheckResponse_ServingStatus = 0
HealthCheckResponse_SERVING HealthCheckResponse_ServingStatus = 1
HealthCheckResponse_NOT_SERVING HealthCheckResponse_ServingStatus = 2
HealthCheckResponse_SERVICE_UNKNOWN HealthCheckResponse_ServingStatus = 3 // Used only by the Watch method.
)
// Enum value maps for HealthCheckResponse_ServingStatus.
var (
HealthCheckResponse_ServingStatus_name = map[int32]string{
0: "UNKNOWN",
1: "SERVING",
2: "NOT_SERVING",
3: "SERVICE_UNKNOWN",
}
HealthCheckResponse_ServingStatus_value = map[string]int32{
"UNKNOWN": 0,
"SERVING": 1,
"NOT_SERVING": 2,
"SERVICE_UNKNOWN": 3,
}
)
func (x HealthCheckResponse_ServingStatus) Enum() *HealthCheckResponse_ServingStatus {
p := new(HealthCheckResponse_ServingStatus)
*p = x
return p
}
func (x HealthCheckResponse_ServingStatus) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (HealthCheckResponse_ServingStatus) Descriptor() protoreflect.EnumDescriptor {
return file_proto_health_proto_enumTypes[0].Descriptor()
}
func (HealthCheckResponse_ServingStatus) Type() protoreflect.EnumType {
return &file_proto_health_proto_enumTypes[0]
}
func (x HealthCheckResponse_ServingStatus) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use HealthCheckResponse_ServingStatus.Descriptor instead.
func (HealthCheckResponse_ServingStatus) EnumDescriptor() ([]byte, []int) {
return file_proto_health_proto_rawDescGZIP(), []int{1, 0}
}
type HealthCheckRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
}
func (x *HealthCheckRequest) Reset() {
*x = HealthCheckRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_health_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HealthCheckRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HealthCheckRequest) ProtoMessage() {}
func (x *HealthCheckRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_health_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use HealthCheckRequest.ProtoReflect.Descriptor instead.
func (*HealthCheckRequest) Descriptor() ([]byte, []int) {
return file_proto_health_proto_rawDescGZIP(), []int{0}
}
func (x *HealthCheckRequest) GetService() string {
if x != nil {
return x.Service
}
return ""
}
type HealthCheckResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Status HealthCheckResponse_ServingStatus `protobuf:"varint,1,opt,name=status,proto3,enum=grpc.health.v1.HealthCheckResponse_ServingStatus" json:"status,omitempty"`
}
func (x *HealthCheckResponse) Reset() {
*x = HealthCheckResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_health_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HealthCheckResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HealthCheckResponse) ProtoMessage() {}
func (x *HealthCheckResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_health_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use HealthCheckResponse.ProtoReflect.Descriptor instead.
func (*HealthCheckResponse) Descriptor() ([]byte, []int) {
return file_proto_health_proto_rawDescGZIP(), []int{1}
}
func (x *HealthCheckResponse) GetStatus() HealthCheckResponse_ServingStatus {
if x != nil {
return x.Status
}
return HealthCheckResponse_UNKNOWN
}
var File_proto_health_proto protoreflect.FileDescriptor
var file_proto_health_proto_rawDesc = []byte{
0x0a, 0x12, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74,
0x68, 0x2e, 0x76, 0x31, 0x22, 0x2e, 0x0a, 0x12, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68,
0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x22, 0xb1, 0x01, 0x0a, 0x13, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43,
0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x06,
0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x31, 0x2e, 0x67,
0x72, 0x70, 0x63, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65,
0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52,
0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x4f, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69,
0x6e, 0x67, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e,
0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x45, 0x52, 0x56, 0x49, 0x4e, 0x47,
0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x4e, 0x4f, 0x54, 0x5f, 0x53, 0x45, 0x52, 0x56, 0x49, 0x4e,
0x47, 0x10, 0x02, 0x12, 0x13, 0x0a, 0x0f, 0x53, 0x45, 0x52, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x55,
0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x03, 0x32, 0xae, 0x01, 0x0a, 0x06, 0x48, 0x65, 0x61,
0x6c, 0x74, 0x68, 0x12, 0x50, 0x0a, 0x05, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x22, 0x2e, 0x67,
0x72, 0x70, 0x63, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65,
0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x23, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2e, 0x76,
0x31, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x52, 0x0a, 0x05, 0x57, 0x61, 0x74, 0x63, 0x68, 0x12, 0x22,
0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x2e,
0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x23, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68,
0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var (
file_proto_health_proto_rawDescOnce sync.Once
file_proto_health_proto_rawDescData = file_proto_health_proto_rawDesc
)
func file_proto_health_proto_rawDescGZIP() []byte {
file_proto_health_proto_rawDescOnce.Do(func() {
file_proto_health_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_health_proto_rawDescData)
})
return file_proto_health_proto_rawDescData
}
var file_proto_health_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_proto_health_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_proto_health_proto_goTypes = []interface{}{
(HealthCheckResponse_ServingStatus)(0), // 0: grpc.health.v1.HealthCheckResponse.ServingStatus
(*HealthCheckRequest)(nil), // 1: grpc.health.v1.HealthCheckRequest
(*HealthCheckResponse)(nil), // 2: grpc.health.v1.HealthCheckResponse
}
var file_proto_health_proto_depIdxs = []int32{
0, // 0: grpc.health.v1.HealthCheckResponse.status:type_name -> grpc.health.v1.HealthCheckResponse.ServingStatus
1, // 1: grpc.health.v1.Health.Check:input_type -> grpc.health.v1.HealthCheckRequest
1, // 2: grpc.health.v1.Health.Watch:input_type -> grpc.health.v1.HealthCheckRequest
2, // 3: grpc.health.v1.Health.Check:output_type -> grpc.health.v1.HealthCheckResponse
2, // 4: grpc.health.v1.Health.Watch:output_type -> grpc.health.v1.HealthCheckResponse
3, // [3:5] is the sub-list for method output_type
1, // [1:3] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_proto_health_proto_init() }
func file_proto_health_proto_init() {
if File_proto_health_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_proto_health_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HealthCheckRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_health_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HealthCheckResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_health_proto_rawDesc,
NumEnums: 1,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_proto_health_proto_goTypes,
DependencyIndexes: file_proto_health_proto_depIdxs,
EnumInfos: file_proto_health_proto_enumTypes,
MessageInfos: file_proto_health_proto_msgTypes,
}.Build()
File_proto_health_proto = out.File
file_proto_health_proto_rawDesc = nil
file_proto_health_proto_goTypes = nil
file_proto_health_proto_depIdxs = nil
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConnInterface
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion6
// HealthClient is the client API for Health service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type HealthClient interface {
Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error)
Watch(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (Health_WatchClient, error)
}
type healthClient struct {
cc grpc.ClientConnInterface
}
func NewHealthClient(cc grpc.ClientConnInterface) HealthClient {
return &healthClient{cc}
}
func (c *healthClient) Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) {
out := new(HealthCheckResponse)
err := c.cc.Invoke(ctx, "/grpc.health.v1.Health/Check", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *healthClient) Watch(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (Health_WatchClient, error) {
stream, err := c.cc.NewStream(ctx, &_Health_serviceDesc.Streams[0], "/grpc.health.v1.Health/Watch", opts...)
if err != nil {
return nil, err
}
x := &healthWatchClient{stream}
if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type Health_WatchClient interface {
Recv() (*HealthCheckResponse, error)
grpc.ClientStream
}
type healthWatchClient struct {
grpc.ClientStream
}
func (x *healthWatchClient) Recv() (*HealthCheckResponse, error) {
m := new(HealthCheckResponse)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// HealthServer is the server API for Health service.
type HealthServer interface {
Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error)
Watch(*HealthCheckRequest, Health_WatchServer) error
}
// UnimplementedHealthServer can be embedded to have forward compatible implementations.
type UnimplementedHealthServer struct {
}
func (*UnimplementedHealthServer) Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Check not implemented")
}
func (*UnimplementedHealthServer) Watch(*HealthCheckRequest, Health_WatchServer) error {
return status.Errorf(codes.Unimplemented, "method Watch not implemented")
}
func RegisterHealthServer(s *grpc.Server, srv HealthServer) {
s.RegisterService(&_Health_serviceDesc, srv)
}
func _Health_Check_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HealthCheckRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HealthServer).Check(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpc.health.v1.Health/Check",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HealthServer).Check(ctx, req.(*HealthCheckRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Health_Watch_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(HealthCheckRequest)
if err := stream.RecvMsg(m); err != nil {
return err
}
return srv.(HealthServer).Watch(m, &healthWatchServer{stream})
}
type Health_WatchServer interface {
Send(*HealthCheckResponse) error
grpc.ServerStream
}
type healthWatchServer struct {
grpc.ServerStream
}
func (x *healthWatchServer) Send(m *HealthCheckResponse) error {
return x.ServerStream.SendMsg(m)
}
var _Health_serviceDesc = grpc.ServiceDesc{
ServiceName: "grpc.health.v1.Health",
HandlerType: (*HealthServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Check",
Handler: _Health_Check_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "Watch",
Handler: _Health_Watch_Handler,
ServerStreams: true,
},
},
Metadata: "proto/health.proto",
}

View File

@ -1,307 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.25.0
// protoc v3.6.1
// source: proto/sample.proto
package proto
import (
context "context"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type SayRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=Name,proto3" json:"Name,omitempty"`
Day string `protobuf:"bytes,2,opt,name=day,proto3" json:"day,omitempty"`
}
func (x *SayRequest) Reset() {
*x = SayRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_sample_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SayRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SayRequest) ProtoMessage() {}
func (x *SayRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_sample_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SayRequest.ProtoReflect.Descriptor instead.
func (*SayRequest) Descriptor() ([]byte, []int) {
return file_proto_sample_proto_rawDescGZIP(), []int{0}
}
func (x *SayRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *SayRequest) GetDay() string {
if x != nil {
return x.Day
}
return ""
}
type SayResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Reply string `protobuf:"bytes,1,opt,name=Reply,proto3" json:"Reply,omitempty"`
}
func (x *SayResponse) Reset() {
*x = SayResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_sample_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SayResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SayResponse) ProtoMessage() {}
func (x *SayResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_sample_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SayResponse.ProtoReflect.Descriptor instead.
func (*SayResponse) Descriptor() ([]byte, []int) {
return file_proto_sample_proto_rawDescGZIP(), []int{1}
}
func (x *SayResponse) GetReply() string {
if x != nil {
return x.Reply
}
return ""
}
var File_proto_sample_proto protoreflect.FileDescriptor
var file_proto_sample_proto_rawDesc = []byte{
0x0a, 0x12, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x22, 0x32, 0x0a, 0x0a,
0x53, 0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x4e, 0x61,
0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x10,
0x0a, 0x03, 0x64, 0x61, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x64, 0x61, 0x79,
0x22, 0x23, 0x0a, 0x0b, 0x53, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x14, 0x0a, 0x05, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
0x52, 0x65, 0x70, 0x6c, 0x79, 0x32, 0x37, 0x0a, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x2e,
0x0a, 0x03, 0x53, 0x61, 0x79, 0x12, 0x12, 0x2e, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x53,
0x61, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x73, 0x61, 0x6d, 0x70,
0x6c, 0x65, 0x2e, 0x53, 0x61, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x07,
0x5a, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_proto_sample_proto_rawDescOnce sync.Once
file_proto_sample_proto_rawDescData = file_proto_sample_proto_rawDesc
)
func file_proto_sample_proto_rawDescGZIP() []byte {
file_proto_sample_proto_rawDescOnce.Do(func() {
file_proto_sample_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_sample_proto_rawDescData)
})
return file_proto_sample_proto_rawDescData
}
var file_proto_sample_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_proto_sample_proto_goTypes = []interface{}{
(*SayRequest)(nil), // 0: sample.SayRequest
(*SayResponse)(nil), // 1: sample.SayResponse
}
var file_proto_sample_proto_depIdxs = []int32{
0, // 0: sample.Hello.Say:input_type -> sample.SayRequest
1, // 1: sample.Hello.Say:output_type -> sample.SayResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_proto_sample_proto_init() }
func file_proto_sample_proto_init() {
if File_proto_sample_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_proto_sample_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SayRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_sample_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SayResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_sample_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_proto_sample_proto_goTypes,
DependencyIndexes: file_proto_sample_proto_depIdxs,
MessageInfos: file_proto_sample_proto_msgTypes,
}.Build()
File_proto_sample_proto = out.File
file_proto_sample_proto_rawDesc = nil
file_proto_sample_proto_goTypes = nil
file_proto_sample_proto_depIdxs = nil
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConnInterface
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion6
// HelloClient is the client API for Hello service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type HelloClient interface {
Say(ctx context.Context, in *SayRequest, opts ...grpc.CallOption) (*SayResponse, error)
}
type helloClient struct {
cc grpc.ClientConnInterface
}
func NewHelloClient(cc grpc.ClientConnInterface) HelloClient {
return &helloClient{cc}
}
func (c *helloClient) Say(ctx context.Context, in *SayRequest, opts ...grpc.CallOption) (*SayResponse, error) {
out := new(SayResponse)
err := c.cc.Invoke(ctx, "/sample.Hello/Say", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// HelloServer is the server API for Hello service.
type HelloServer interface {
Say(context.Context, *SayRequest) (*SayResponse, error)
}
// UnimplementedHelloServer can be embedded to have forward compatible implementations.
type UnimplementedHelloServer struct {
}
func (*UnimplementedHelloServer) Say(context.Context, *SayRequest) (*SayResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Say not implemented")
}
func RegisterHelloServer(s *grpc.Server, srv HelloServer) {
s.RegisterService(&_Hello_serviceDesc, srv)
}
func _Hello_Say_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SayRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HelloServer).Say(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/sample.Hello/Say",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HelloServer).Say(ctx, req.(*SayRequest))
}
return interceptor(ctx, in, info, handler)
}
var _Hello_serviceDesc = grpc.ServiceDesc{
ServiceName: "sample.Hello",
HandlerType: (*HelloServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Say",
Handler: _Hello_Say_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "proto/sample.proto",
}