From ea5a986da6409f8f7ee866f592a80f33319ba092 Mon Sep 17 00:00:00 2001 From: realityone Date: Sun, 18 Feb 2024 19:57:08 +0800 Subject: [PATCH 01/11] https client --- api/gateway/config/v1/gateway.pb.go | 406 ++++++++++++------ api/gateway/config/v1/gateway.proto | 9 + .../circuitbreaker/v1/circuitbreaker.pb.go | 2 +- api/gateway/middleware/cors/v1/cors.pb.go | 2 +- .../middleware/logging/v1/logging.pb.go | 2 +- .../middleware/rewrite/v1/rewrite.pb.go | 2 +- .../middleware/tracing/v1/tracing.pb.go | 2 +- client/client_test.go | 14 + client/node.go | 55 ++- go.mod | 6 +- go.sum | 12 +- 11 files changed, 350 insertions(+), 162 deletions(-) diff --git a/api/gateway/config/v1/gateway.pb.go b/api/gateway/config/v1/gateway.pb.go index e5e7b777..a2b422bd 100644 --- a/api/gateway/config/v1/gateway.pb.go +++ b/api/gateway/config/v1/gateway.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v4.23.4 +// protoc v4.25.1 // source: gateway/config/v1/gateway.proto package v1 @@ -79,9 +79,10 @@ type Gateway struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // Deprecated: Marked as deprecated in gateway/config/v1/gateway.proto. - Hosts []string `protobuf:"bytes,3,rep,name=hosts,proto3" json:"hosts,omitempty"` - Endpoints []*Endpoint `protobuf:"bytes,4,rep,name=endpoints,proto3" json:"endpoints,omitempty"` - Middlewares []*Middleware `protobuf:"bytes,5,rep,name=middlewares,proto3" json:"middlewares,omitempty"` + Hosts []string `protobuf:"bytes,3,rep,name=hosts,proto3" json:"hosts,omitempty"` + Endpoints []*Endpoint `protobuf:"bytes,4,rep,name=endpoints,proto3" json:"endpoints,omitempty"` + Middlewares []*Middleware `protobuf:"bytes,5,rep,name=middlewares,proto3" json:"middlewares,omitempty"` + TlsStore map[string]*TLS `protobuf:"bytes,6,rep,name=tls_store,json=tlsStore,proto3" json:"tls_store,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *Gateway) Reset() { @@ -152,6 +153,84 @@ func (x *Gateway) GetMiddlewares() []*Middleware { return nil } +func (x *Gateway) GetTlsStore() map[string]*TLS { + if x != nil { + return x.TlsStore + } + return nil +} + +type TLS struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Verify bool `protobuf:"varint,1,opt,name=verify,proto3" json:"verify,omitempty"` + Cacert string `protobuf:"bytes,2,opt,name=cacert,proto3" json:"cacert,omitempty"` + Cert string `protobuf:"bytes,3,opt,name=cert,proto3" json:"cert,omitempty"` + Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *TLS) Reset() { + *x = TLS{} + if protoimpl.UnsafeEnabled { + mi := &file_gateway_config_v1_gateway_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TLS) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TLS) ProtoMessage() {} + +func (x *TLS) ProtoReflect() protoreflect.Message { + mi := &file_gateway_config_v1_gateway_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 TLS.ProtoReflect.Descriptor instead. +func (*TLS) Descriptor() ([]byte, []int) { + return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{1} +} + +func (x *TLS) GetVerify() bool { + if x != nil { + return x.Verify + } + return false +} + +func (x *TLS) GetCacert() string { + if x != nil { + return x.Cacert + } + return "" +} + +func (x *TLS) GetCert() string { + if x != nil { + return x.Cert + } + return "" +} + +func (x *TLS) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + type Endpoint struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -172,7 +251,7 @@ type Endpoint struct { func (x *Endpoint) Reset() { *x = Endpoint{} if protoimpl.UnsafeEnabled { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[1] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -185,7 +264,7 @@ func (x *Endpoint) String() string { func (*Endpoint) ProtoMessage() {} func (x *Endpoint) ProtoReflect() protoreflect.Message { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[1] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -198,7 +277,7 @@ func (x *Endpoint) ProtoReflect() protoreflect.Message { // Deprecated: Use Endpoint.ProtoReflect.Descriptor instead. func (*Endpoint) Descriptor() ([]byte, []int) { - return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{1} + return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{2} } func (x *Endpoint) GetPath() string { @@ -284,7 +363,7 @@ type Middleware struct { func (x *Middleware) Reset() { *x = Middleware{} if protoimpl.UnsafeEnabled { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[2] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -297,7 +376,7 @@ func (x *Middleware) String() string { func (*Middleware) ProtoMessage() {} func (x *Middleware) ProtoReflect() protoreflect.Message { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[2] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -310,7 +389,7 @@ func (x *Middleware) ProtoReflect() protoreflect.Message { // Deprecated: Use Middleware.ProtoReflect.Descriptor instead. func (*Middleware) Descriptor() ([]byte, []int) { - return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{2} + return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{3} } func (x *Middleware) GetName() string { @@ -345,12 +424,13 @@ type Backend struct { Target string `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"` Weight *int64 `protobuf:"varint,2,opt,name=weight,proto3,oneof" json:"weight,omitempty"` HealthCheck *HealthCheck `protobuf:"bytes,3,opt,name=health_check,json=healthCheck,proto3" json:"health_check,omitempty"` + Tls string `protobuf:"bytes,4,opt,name=tls,proto3" json:"tls,omitempty"` } func (x *Backend) Reset() { *x = Backend{} if protoimpl.UnsafeEnabled { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[3] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -363,7 +443,7 @@ func (x *Backend) String() string { func (*Backend) ProtoMessage() {} func (x *Backend) ProtoReflect() protoreflect.Message { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[3] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -376,7 +456,7 @@ func (x *Backend) ProtoReflect() protoreflect.Message { // Deprecated: Use Backend.ProtoReflect.Descriptor instead. func (*Backend) Descriptor() ([]byte, []int) { - return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{3} + return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{4} } func (x *Backend) GetTarget() string { @@ -400,6 +480,13 @@ func (x *Backend) GetHealthCheck() *HealthCheck { return nil } +func (x *Backend) GetTls() string { + if x != nil { + return x.Tls + } + return "" +} + type HealthCheck struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -409,7 +496,7 @@ type HealthCheck struct { func (x *HealthCheck) Reset() { *x = HealthCheck{} if protoimpl.UnsafeEnabled { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[4] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -422,7 +509,7 @@ func (x *HealthCheck) String() string { func (*HealthCheck) ProtoMessage() {} func (x *HealthCheck) ProtoReflect() protoreflect.Message { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[4] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -435,7 +522,7 @@ func (x *HealthCheck) ProtoReflect() protoreflect.Message { // Deprecated: Use HealthCheck.ProtoReflect.Descriptor instead. func (*HealthCheck) Descriptor() ([]byte, []int) { - return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{4} + return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{5} } type Retry struct { @@ -454,7 +541,7 @@ type Retry struct { func (x *Retry) Reset() { *x = Retry{} if protoimpl.UnsafeEnabled { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[5] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -467,7 +554,7 @@ func (x *Retry) String() string { func (*Retry) ProtoMessage() {} func (x *Retry) ProtoReflect() protoreflect.Message { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[5] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -480,7 +567,7 @@ func (x *Retry) ProtoReflect() protoreflect.Message { // Deprecated: Use Retry.ProtoReflect.Descriptor instead. func (*Retry) Descriptor() ([]byte, []int) { - return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{5} + return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{6} } func (x *Retry) GetAttempts() uint32 { @@ -526,7 +613,7 @@ type Condition struct { func (x *Condition) Reset() { *x = Condition{} if protoimpl.UnsafeEnabled { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[6] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -539,7 +626,7 @@ func (x *Condition) String() string { func (*Condition) ProtoMessage() {} func (x *Condition) ProtoReflect() protoreflect.Message { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[6] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -552,7 +639,7 @@ func (x *Condition) ProtoReflect() protoreflect.Message { // Deprecated: Use Condition.ProtoReflect.Descriptor instead. func (*Condition) Descriptor() ([]byte, []int) { - return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{6} + return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{7} } func (m *Condition) GetCondition() isCondition_Condition { @@ -606,7 +693,7 @@ type ConditionHeader struct { func (x *ConditionHeader) Reset() { *x = ConditionHeader{} if protoimpl.UnsafeEnabled { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[8] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -619,7 +706,7 @@ func (x *ConditionHeader) String() string { func (*ConditionHeader) ProtoMessage() {} func (x *ConditionHeader) ProtoReflect() protoreflect.Message { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[8] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -632,7 +719,7 @@ func (x *ConditionHeader) ProtoReflect() protoreflect.Message { // Deprecated: Use ConditionHeader.ProtoReflect.Descriptor instead. func (*ConditionHeader) Descriptor() ([]byte, []int) { - return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{6, 0} + return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{7, 0} } func (x *ConditionHeader) GetName() string { @@ -659,7 +746,7 @@ var file_gateway_config_v1_gateway_proto_rawDesc = []byte{ 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, - 0xcd, 0x01, 0x0a, 0x07, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0xe9, 0x02, 0x0a, 0x07, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x05, 0x68, 0x6f, 0x73, @@ -671,88 +758,105 @@ var file_gateway_config_v1_gateway_proto_rawDesc = []byte{ 0x0a, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, - 0x72, 0x65, 0x52, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x73, 0x22, - 0x87, 0x04, 0x0a, 0x08, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, - 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, - 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, - 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, - 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x37, 0x0a, 0x08, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x67, + 0x72, 0x65, 0x52, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x73, 0x12, + 0x45, 0x0a, 0x09, 0x74, 0x6c, 0x73, 0x5f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x18, 0x06, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, + 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x54, + 0x6c, 0x73, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x74, 0x6c, + 0x73, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x1a, 0x53, 0x0a, 0x0d, 0x54, 0x6c, 0x73, 0x53, 0x74, 0x6f, + 0x72, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2c, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, + 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x4c, 0x53, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x5b, 0x0a, 0x03, 0x54, + 0x4c, 0x53, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x61, + 0x63, 0x65, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x61, 0x63, 0x65, + 0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x65, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x63, 0x65, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x87, 0x04, 0x0a, 0x08, 0x45, 0x6e, 0x64, + 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, + 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x37, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, + 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, + 0x6f, 0x6c, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x33, 0x0a, 0x07, + 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, + 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x73, + 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, + 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x69, 0x64, 0x64, 0x6c, + 0x65, 0x77, 0x61, 0x72, 0x65, 0x52, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, + 0x65, 0x73, 0x12, 0x36, 0x0a, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x07, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, + 0x52, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x2e, 0x0a, 0x05, 0x72, 0x65, + 0x74, 0x72, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, + 0x74, 0x72, 0x79, 0x52, 0x05, 0x72, 0x65, 0x74, 0x72, 0x79, 0x12, 0x45, 0x0a, 0x08, 0x6d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, - 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x63, 0x6f, 0x6c, 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x6d, 0x69, 0x64, 0x64, - 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, + 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x68, 0x6f, 0x73, 0x74, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, + 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x22, 0x6c, 0x0a, 0x0a, 0x4d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, + 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x6f, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, + 0x22, 0x9e, 0x01, 0x0a, 0x07, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, + 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x61, + 0x72, 0x67, 0x65, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x88, 0x01, + 0x01, 0x12, 0x41, 0x0a, 0x0c, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x5f, 0x63, 0x68, 0x65, 0x63, + 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, 0x61, 0x6c, + 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x0b, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, + 0x68, 0x65, 0x63, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x74, 0x6c, 0x73, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, + 0x74, 0x22, 0x0d, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, + 0x22, 0xc4, 0x01, 0x0a, 0x05, 0x52, 0x65, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x74, + 0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x74, + 0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, 0x12, 0x41, 0x0a, 0x0f, 0x70, 0x65, 0x72, 0x5f, 0x74, 0x72, + 0x79, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x70, 0x65, 0x72, 0x54, + 0x72, 0x79, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, + 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, - 0x31, 0x2e, 0x4d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x52, 0x0b, 0x6d, 0x69, - 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x73, 0x12, 0x36, 0x0a, 0x08, 0x62, 0x61, 0x63, - 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x61, - 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, - 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x52, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, - 0x73, 0x12, 0x2e, 0x0a, 0x05, 0x72, 0x65, 0x74, 0x72, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x18, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x74, 0x72, 0x79, 0x52, 0x05, 0x72, 0x65, 0x74, 0x72, - 0x79, 0x12, 0x45, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x09, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, - 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, - 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, - 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x1a, 0x3b, 0x0a, 0x0d, - 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, + 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, + 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x69, + 0x6f, 0x72, 0x69, 0x74, 0x69, 0x65, 0x73, 0x22, 0xb8, 0x01, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x64, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x0e, 0x62, 0x79, 0x5f, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, + 0x0c, 0x62, 0x79, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x42, 0x0a, + 0x09, 0x62, 0x79, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x23, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x68, + 0x65, 0x61, 0x64, 0x65, 0x72, 0x48, 0x00, 0x52, 0x08, 0x62, 0x79, 0x48, 0x65, 0x61, 0x64, 0x65, + 0x72, 0x1a, 0x32, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x6c, 0x0a, 0x0a, 0x4d, 0x69, 0x64, - 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x6f, - 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, - 0x6e, 0x79, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x72, - 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, - 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x8c, 0x01, 0x0a, 0x07, 0x42, 0x61, 0x63, 0x6b, - 0x65, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x77, - 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x06, 0x77, - 0x65, 0x69, 0x67, 0x68, 0x74, 0x88, 0x01, 0x01, 0x12, 0x41, 0x0a, 0x0c, 0x68, 0x65, 0x61, 0x6c, - 0x74, 0x68, 0x5f, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, - 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, - 0x76, 0x31, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x0b, - 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x42, 0x09, 0x0a, 0x07, 0x5f, - 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x0d, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, - 0x43, 0x68, 0x65, 0x63, 0x6b, 0x22, 0xc4, 0x01, 0x0a, 0x05, 0x52, 0x65, 0x74, 0x72, 0x79, 0x12, - 0x1a, 0x0a, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, 0x12, 0x41, 0x0a, 0x0f, 0x70, - 0x65, 0x72, 0x5f, 0x74, 0x72, 0x79, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x0d, 0x70, 0x65, 0x72, 0x54, 0x72, 0x79, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, - 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, - 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x0a, - 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, - 0x52, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x69, 0x65, 0x73, 0x22, 0xb8, 0x01, 0x0a, - 0x09, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x0e, 0x62, 0x79, - 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x48, 0x00, 0x52, 0x0c, 0x62, 0x79, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, - 0x64, 0x65, 0x12, 0x42, 0x0a, 0x09, 0x62, 0x79, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, - 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x48, 0x00, 0x52, 0x08, 0x62, 0x79, - 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x1a, 0x32, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, - 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x63, 0x6f, - 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2a, 0x2f, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x74, 0x6f, - 0x63, 0x6f, 0x6c, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, - 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x10, 0x01, 0x12, 0x08, - 0x0a, 0x04, 0x47, 0x52, 0x50, 0x43, 0x10, 0x02, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, - 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x61, 0x74, - 0x65, 0x77, 0x61, 0x79, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x76, 0x31, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x2a, 0x2f, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0f, + 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, + 0x08, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x47, 0x52, 0x50, + 0x43, 0x10, 0x02, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, + 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -768,40 +872,44 @@ func file_gateway_config_v1_gateway_proto_rawDescGZIP() []byte { } var file_gateway_config_v1_gateway_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_gateway_config_v1_gateway_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_gateway_config_v1_gateway_proto_msgTypes = make([]protoimpl.MessageInfo, 11) var file_gateway_config_v1_gateway_proto_goTypes = []interface{}{ (Protocol)(0), // 0: gateway.config.v1.Protocol (*Gateway)(nil), // 1: gateway.config.v1.Gateway - (*Endpoint)(nil), // 2: gateway.config.v1.Endpoint - (*Middleware)(nil), // 3: gateway.config.v1.Middleware - (*Backend)(nil), // 4: gateway.config.v1.Backend - (*HealthCheck)(nil), // 5: gateway.config.v1.HealthCheck - (*Retry)(nil), // 6: gateway.config.v1.Retry - (*Condition)(nil), // 7: gateway.config.v1.Condition - nil, // 8: gateway.config.v1.Endpoint.MetadataEntry - (*ConditionHeader)(nil), // 9: gateway.config.v1.Condition.header - (*durationpb.Duration)(nil), // 10: google.protobuf.Duration - (*anypb.Any)(nil), // 11: google.protobuf.Any + (*TLS)(nil), // 2: gateway.config.v1.TLS + (*Endpoint)(nil), // 3: gateway.config.v1.Endpoint + (*Middleware)(nil), // 4: gateway.config.v1.Middleware + (*Backend)(nil), // 5: gateway.config.v1.Backend + (*HealthCheck)(nil), // 6: gateway.config.v1.HealthCheck + (*Retry)(nil), // 7: gateway.config.v1.Retry + (*Condition)(nil), // 8: gateway.config.v1.Condition + nil, // 9: gateway.config.v1.Gateway.TlsStoreEntry + nil, // 10: gateway.config.v1.Endpoint.MetadataEntry + (*ConditionHeader)(nil), // 11: gateway.config.v1.Condition.header + (*durationpb.Duration)(nil), // 12: google.protobuf.Duration + (*anypb.Any)(nil), // 13: google.protobuf.Any } var file_gateway_config_v1_gateway_proto_depIdxs = []int32{ - 2, // 0: gateway.config.v1.Gateway.endpoints:type_name -> gateway.config.v1.Endpoint - 3, // 1: gateway.config.v1.Gateway.middlewares:type_name -> gateway.config.v1.Middleware - 0, // 2: gateway.config.v1.Endpoint.protocol:type_name -> gateway.config.v1.Protocol - 10, // 3: gateway.config.v1.Endpoint.timeout:type_name -> google.protobuf.Duration - 3, // 4: gateway.config.v1.Endpoint.middlewares:type_name -> gateway.config.v1.Middleware - 4, // 5: gateway.config.v1.Endpoint.backends:type_name -> gateway.config.v1.Backend - 6, // 6: gateway.config.v1.Endpoint.retry:type_name -> gateway.config.v1.Retry - 8, // 7: gateway.config.v1.Endpoint.metadata:type_name -> gateway.config.v1.Endpoint.MetadataEntry - 11, // 8: gateway.config.v1.Middleware.options:type_name -> google.protobuf.Any - 5, // 9: gateway.config.v1.Backend.health_check:type_name -> gateway.config.v1.HealthCheck - 10, // 10: gateway.config.v1.Retry.per_try_timeout:type_name -> google.protobuf.Duration - 7, // 11: gateway.config.v1.Retry.conditions:type_name -> gateway.config.v1.Condition - 9, // 12: gateway.config.v1.Condition.by_header:type_name -> gateway.config.v1.Condition.header - 13, // [13:13] is the sub-list for method output_type - 13, // [13:13] is the sub-list for method input_type - 13, // [13:13] is the sub-list for extension type_name - 13, // [13:13] is the sub-list for extension extendee - 0, // [0:13] is the sub-list for field type_name + 3, // 0: gateway.config.v1.Gateway.endpoints:type_name -> gateway.config.v1.Endpoint + 4, // 1: gateway.config.v1.Gateway.middlewares:type_name -> gateway.config.v1.Middleware + 9, // 2: gateway.config.v1.Gateway.tls_store:type_name -> gateway.config.v1.Gateway.TlsStoreEntry + 0, // 3: gateway.config.v1.Endpoint.protocol:type_name -> gateway.config.v1.Protocol + 12, // 4: gateway.config.v1.Endpoint.timeout:type_name -> google.protobuf.Duration + 4, // 5: gateway.config.v1.Endpoint.middlewares:type_name -> gateway.config.v1.Middleware + 5, // 6: gateway.config.v1.Endpoint.backends:type_name -> gateway.config.v1.Backend + 7, // 7: gateway.config.v1.Endpoint.retry:type_name -> gateway.config.v1.Retry + 10, // 8: gateway.config.v1.Endpoint.metadata:type_name -> gateway.config.v1.Endpoint.MetadataEntry + 13, // 9: gateway.config.v1.Middleware.options:type_name -> google.protobuf.Any + 6, // 10: gateway.config.v1.Backend.health_check:type_name -> gateway.config.v1.HealthCheck + 12, // 11: gateway.config.v1.Retry.per_try_timeout:type_name -> google.protobuf.Duration + 8, // 12: gateway.config.v1.Retry.conditions:type_name -> gateway.config.v1.Condition + 11, // 13: gateway.config.v1.Condition.by_header:type_name -> gateway.config.v1.Condition.header + 2, // 14: gateway.config.v1.Gateway.TlsStoreEntry.value:type_name -> gateway.config.v1.TLS + 15, // [15:15] is the sub-list for method output_type + 15, // [15:15] is the sub-list for method input_type + 15, // [15:15] is the sub-list for extension type_name + 15, // [15:15] is the sub-list for extension extendee + 0, // [0:15] is the sub-list for field type_name } func init() { file_gateway_config_v1_gateway_proto_init() } @@ -823,7 +931,7 @@ func file_gateway_config_v1_gateway_proto_init() { } } file_gateway_config_v1_gateway_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Endpoint); i { + switch v := v.(*TLS); i { case 0: return &v.state case 1: @@ -835,7 +943,7 @@ func file_gateway_config_v1_gateway_proto_init() { } } file_gateway_config_v1_gateway_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Middleware); i { + switch v := v.(*Endpoint); i { case 0: return &v.state case 1: @@ -847,7 +955,7 @@ func file_gateway_config_v1_gateway_proto_init() { } } file_gateway_config_v1_gateway_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Backend); i { + switch v := v.(*Middleware); i { case 0: return &v.state case 1: @@ -859,7 +967,7 @@ func file_gateway_config_v1_gateway_proto_init() { } } file_gateway_config_v1_gateway_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HealthCheck); i { + switch v := v.(*Backend); i { case 0: return &v.state case 1: @@ -871,7 +979,7 @@ func file_gateway_config_v1_gateway_proto_init() { } } file_gateway_config_v1_gateway_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Retry); i { + switch v := v.(*HealthCheck); i { case 0: return &v.state case 1: @@ -883,6 +991,18 @@ func file_gateway_config_v1_gateway_proto_init() { } } file_gateway_config_v1_gateway_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Retry); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_gateway_config_v1_gateway_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Condition); i { case 0: return &v.state @@ -894,7 +1014,7 @@ func file_gateway_config_v1_gateway_proto_init() { return nil } } - file_gateway_config_v1_gateway_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_gateway_config_v1_gateway_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ConditionHeader); i { case 0: return &v.state @@ -907,8 +1027,8 @@ func file_gateway_config_v1_gateway_proto_init() { } } } - file_gateway_config_v1_gateway_proto_msgTypes[3].OneofWrappers = []interface{}{} - file_gateway_config_v1_gateway_proto_msgTypes[6].OneofWrappers = []interface{}{ + file_gateway_config_v1_gateway_proto_msgTypes[4].OneofWrappers = []interface{}{} + file_gateway_config_v1_gateway_proto_msgTypes[7].OneofWrappers = []interface{}{ (*Condition_ByStatusCode)(nil), (*Condition_ByHeader)(nil), } @@ -918,7 +1038,7 @@ func file_gateway_config_v1_gateway_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_gateway_config_v1_gateway_proto_rawDesc, NumEnums: 1, - NumMessages: 9, + NumMessages: 11, NumExtensions: 0, NumServices: 0, }, diff --git a/api/gateway/config/v1/gateway.proto b/api/gateway/config/v1/gateway.proto index f6062287..5a015afa 100644 --- a/api/gateway/config/v1/gateway.proto +++ b/api/gateway/config/v1/gateway.proto @@ -13,6 +13,14 @@ message Gateway { repeated string hosts = 3 [deprecated = true]; repeated Endpoint endpoints = 4; repeated Middleware middlewares = 5; + map tls_store = 6; +} + +message TLS { + bool verify = 1; + string cacert = 2; + string cert = 3; + string key = 4; } message Endpoint { @@ -41,6 +49,7 @@ message Backend { string target = 1; optional int64 weight = 2; HealthCheck health_check = 3; + string tls = 4; } enum Protocol { diff --git a/api/gateway/middleware/circuitbreaker/v1/circuitbreaker.pb.go b/api/gateway/middleware/circuitbreaker/v1/circuitbreaker.pb.go index 456178aa..536416af 100644 --- a/api/gateway/middleware/circuitbreaker/v1/circuitbreaker.pb.go +++ b/api/gateway/middleware/circuitbreaker/v1/circuitbreaker.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v4.23.4 +// protoc v4.25.1 // source: gateway/middleware/circuitbreaker/v1/circuitbreaker.proto package v1 diff --git a/api/gateway/middleware/cors/v1/cors.pb.go b/api/gateway/middleware/cors/v1/cors.pb.go index 0937137e..6e4ea40f 100644 --- a/api/gateway/middleware/cors/v1/cors.pb.go +++ b/api/gateway/middleware/cors/v1/cors.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v4.23.4 +// protoc v4.25.1 // source: gateway/middleware/cors/v1/cors.proto package v1 diff --git a/api/gateway/middleware/logging/v1/logging.pb.go b/api/gateway/middleware/logging/v1/logging.pb.go index f8236fac..8408550b 100644 --- a/api/gateway/middleware/logging/v1/logging.pb.go +++ b/api/gateway/middleware/logging/v1/logging.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v4.23.4 +// protoc v4.25.1 // source: gateway/middleware/logging/v1/logging.proto package v1 diff --git a/api/gateway/middleware/rewrite/v1/rewrite.pb.go b/api/gateway/middleware/rewrite/v1/rewrite.pb.go index 469564a3..639a7e46 100644 --- a/api/gateway/middleware/rewrite/v1/rewrite.pb.go +++ b/api/gateway/middleware/rewrite/v1/rewrite.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v4.23.4 +// protoc v4.25.1 // source: gateway/middleware/rewrite/v1/rewrite.proto package v1 diff --git a/api/gateway/middleware/tracing/v1/tracing.pb.go b/api/gateway/middleware/tracing/v1/tracing.pb.go index 99edad39..99b7451e 100644 --- a/api/gateway/middleware/tracing/v1/tracing.pb.go +++ b/api/gateway/middleware/tracing/v1/tracing.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.31.0 -// protoc v4.23.4 +// protoc v4.25.1 // source: gateway/middleware/tracing/v1/tracing.proto package v1 diff --git a/client/client_test.go b/client/client_test.go index da13c8ef..9ba219a4 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1 +1,15 @@ package client + +import ( + "fmt" + "testing" +) + +func TestRequestHTTPS(t *testing.T) { + resp, err := _globalHTTPSClient.Get("https://www.bilibili.com") + if err != nil { + panic(err) + } + defer resp.Body.Close() + fmt.Println("RESP", resp.Proto, resp.Status, resp.StatusCode) +} diff --git a/client/node.go b/client/node.go index 0b01d4a4..fc9c66a5 100644 --- a/client/node.go +++ b/client/node.go @@ -19,7 +19,8 @@ import ( var _ selector.Node = &node{} var _globalClient = defaultClient() -var _globalH2Client = defaultH2Client() +var _globalH2CClient = defaultH2CClient() +var _globalHTTPSClient = defaultHTTPSClient() var _dialTimeout = 200 * time.Millisecond var followRedirect = false @@ -77,7 +78,7 @@ func defaultClient() *http.Client { } } -func defaultH2Client() *http.Client { +func defaultH2CClient() *http.Client { return &http.Client{ CheckRedirect: defaultCheckRedirect, Transport: &http2.Transport{ @@ -93,6 +94,50 @@ func defaultH2Client() *http.Client { } } +func defaultHTTPSClient() *http.Client { + tr := &http.Transport{ + // TLSClientConfig: , + Proxy: http.ProxyFromEnvironment, + DialContext: (&net.Dialer{ + Timeout: _dialTimeout, + KeepAlive: 30 * time.Second, + }).DialContext, + MaxIdleConns: 10000, + MaxIdleConnsPerHost: 1000, + MaxConnsPerHost: 1000, + DisableCompression: true, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + } + _ = http2.ConfigureTransport(tr) + return &http.Client{ + CheckRedirect: defaultCheckRedirect, + Transport: tr, + } +} + +// func getTLSClient() *http.Client { +// return &http.Client{ +// CheckRedirect: defaultCheckRedirect, +// Transport: &http.Transport{ +// Proxy: http.ProxyFromEnvironment, +// // TLSClientConfig: , +// DialContext: (&net.Dialer{ +// Timeout: _dialTimeout, +// KeepAlive: 30 * time.Second, +// }).DialContext, +// MaxIdleConns: 10000, +// MaxIdleConnsPerHost: 1000, +// MaxConnsPerHost: 1000, +// DisableCompression: true, +// IdleConnTimeout: 90 * time.Second, +// TLSHandshakeTimeout: 10 * time.Second, +// ExpectContinueTimeout: 1 * time.Second, +// }, +// } +// } + func newNode(addr string, protocol config.Protocol, weight *int64, md map[string]string, version string, name string) *node { node := &node{ protocol: protocol, @@ -102,11 +147,11 @@ func newNode(addr string, protocol config.Protocol, weight *int64, md map[string version: version, name: name, } + node.client = _globalClient if protocol == config.Protocol_GRPC { - node.client = _globalH2Client - } else { - node.client = _globalClient + node.client = _globalH2CClient } + return node } diff --git a/go.mod b/go.mod index 6c326371..369ee61c 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( go.uber.org/atomic v1.11.0 go.uber.org/automaxprocs v1.4.0 golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 - golang.org/x/net v0.1.0 + golang.org/x/net v0.21.0 google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd google.golang.org/protobuf v1.28.0 sigs.k8s.io/yaml v1.3.0 @@ -62,8 +62,8 @@ require ( go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.4.1 // indirect go.opentelemetry.io/proto/otlp v0.12.0 // indirect golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/text v0.4.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/grpc v1.46.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index c3aa9a02..db4bb6df 100644 --- a/go.sum +++ b/go.sum @@ -462,8 +462,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= -golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -540,8 +540,8 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -550,8 +550,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From edea061dbce57bdb319d081404e3432b7d26fd0a Mon Sep 17 00:00:00 2001 From: realityone Date: Mon, 19 Feb 2024 14:21:41 +0800 Subject: [PATCH 02/11] client side tls support --- api/gateway/config/v1/gateway.pb.go | 208 +++++++++++++++------------- api/gateway/config/v1/gateway.proto | 5 +- client/factory.go | 33 ++++- client/node.go | 90 ++++++++---- proxy/proxy.go | 1 + 5 files changed, 207 insertions(+), 130 deletions(-) diff --git a/api/gateway/config/v1/gateway.pb.go b/api/gateway/config/v1/gateway.pb.go index a2b422bd..2e7fe507 100644 --- a/api/gateway/config/v1/gateway.pb.go +++ b/api/gateway/config/v1/gateway.pb.go @@ -165,10 +165,10 @@ type TLS struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Verify bool `protobuf:"varint,1,opt,name=verify,proto3" json:"verify,omitempty"` - Cacert string `protobuf:"bytes,2,opt,name=cacert,proto3" json:"cacert,omitempty"` - Cert string `protobuf:"bytes,3,opt,name=cert,proto3" json:"cert,omitempty"` - Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` + Insecure bool `protobuf:"varint,1,opt,name=insecure,proto3" json:"insecure,omitempty"` + Cacert string `protobuf:"bytes,2,opt,name=cacert,proto3" json:"cacert,omitempty"` + Cert string `protobuf:"bytes,3,opt,name=cert,proto3" json:"cert,omitempty"` + Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` } func (x *TLS) Reset() { @@ -203,9 +203,9 @@ func (*TLS) Descriptor() ([]byte, []int) { return file_gateway_config_v1_gateway_proto_rawDescGZIP(), []int{1} } -func (x *TLS) GetVerify() bool { +func (x *TLS) GetInsecure() bool { if x != nil { - return x.Verify + return x.Insecure } return false } @@ -421,10 +421,11 @@ type Backend struct { // localhost // 127.0.0.1:8000 // discovery:///service_name - Target string `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"` - Weight *int64 `protobuf:"varint,2,opt,name=weight,proto3,oneof" json:"weight,omitempty"` - HealthCheck *HealthCheck `protobuf:"bytes,3,opt,name=health_check,json=healthCheck,proto3" json:"health_check,omitempty"` - Tls string `protobuf:"bytes,4,opt,name=tls,proto3" json:"tls,omitempty"` + Target string `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"` + Weight *int64 `protobuf:"varint,2,opt,name=weight,proto3,oneof" json:"weight,omitempty"` + HealthCheck *HealthCheck `protobuf:"bytes,3,opt,name=health_check,json=healthCheck,proto3" json:"health_check,omitempty"` + Tls bool `protobuf:"varint,4,opt,name=tls,proto3" json:"tls,omitempty"` + TlsConfigName string `protobuf:"bytes,5,opt,name=tls_config_name,json=tlsConfigName,proto3" json:"tls_config_name,omitempty"` } func (x *Backend) Reset() { @@ -480,10 +481,17 @@ func (x *Backend) GetHealthCheck() *HealthCheck { return nil } -func (x *Backend) GetTls() string { +func (x *Backend) GetTls() bool { if x != nil { return x.Tls } + return false +} + +func (x *Backend) GetTlsConfigName() string { + if x != nil { + return x.TlsConfigName + } return "" } @@ -768,95 +776,97 @@ var file_gateway_config_v1_gateway_proto_rawDesc = []byte{ 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2c, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x4c, 0x53, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x5b, 0x0a, 0x03, 0x54, - 0x4c, 0x53, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x06, 0x76, 0x65, 0x72, 0x69, 0x66, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x61, - 0x63, 0x65, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x61, 0x63, 0x65, - 0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x65, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x63, 0x65, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x87, 0x04, 0x0a, 0x08, 0x45, 0x6e, 0x64, - 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, - 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, - 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x12, 0x37, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, - 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, - 0x6f, 0x6c, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x33, 0x0a, 0x07, - 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, - 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x73, - 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, - 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x69, 0x64, 0x64, 0x6c, - 0x65, 0x77, 0x61, 0x72, 0x65, 0x52, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, - 0x65, 0x73, 0x12, 0x36, 0x0a, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x07, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, - 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, - 0x52, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x2e, 0x0a, 0x05, 0x72, 0x65, - 0x74, 0x72, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x67, 0x61, 0x74, 0x65, - 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, - 0x74, 0x72, 0x79, 0x52, 0x05, 0x72, 0x65, 0x74, 0x72, 0x79, 0x12, 0x45, 0x0a, 0x08, 0x6d, 0x65, - 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x67, - 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, - 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, - 0x61, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x68, 0x6f, 0x73, 0x74, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, - 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, - 0x38, 0x01, 0x22, 0x6c, 0x0a, 0x0a, 0x4d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, - 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x6f, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, - 0x22, 0x9e, 0x01, 0x0a, 0x07, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, - 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x61, - 0x72, 0x67, 0x65, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x88, 0x01, - 0x01, 0x12, 0x41, 0x0a, 0x0c, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x5f, 0x63, 0x68, 0x65, 0x63, - 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, - 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, 0x61, 0x6c, - 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x0b, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, - 0x68, 0x65, 0x63, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x74, 0x6c, 0x73, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, - 0x74, 0x22, 0x0d, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, - 0x22, 0xc4, 0x01, 0x0a, 0x05, 0x52, 0x65, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x74, - 0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x74, - 0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, 0x12, 0x41, 0x0a, 0x0f, 0x70, 0x65, 0x72, 0x5f, 0x74, 0x72, - 0x79, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x70, 0x65, 0x72, 0x54, - 0x72, 0x79, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, - 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x5f, 0x0a, 0x03, 0x54, + 0x4c, 0x53, 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x12, 0x16, + 0x0a, 0x06, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x65, 0x72, 0x74, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x65, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x87, 0x04, 0x0a, + 0x08, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, + 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x16, 0x0a, + 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, + 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, + 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x37, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x63, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, + 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, + 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, + 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, + 0x61, 0x72, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x67, 0x61, 0x74, + 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, + 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x52, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, + 0x65, 0x77, 0x61, 0x72, 0x65, 0x73, 0x12, 0x36, 0x0a, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, + 0x64, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, + 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x63, + 0x6b, 0x65, 0x6e, 0x64, 0x52, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x2e, + 0x0a, 0x05, 0x72, 0x65, 0x74, 0x72, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, - 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, - 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, - 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x69, - 0x6f, 0x72, 0x69, 0x74, 0x69, 0x65, 0x73, 0x22, 0xb8, 0x01, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x64, - 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x0e, 0x62, 0x79, 0x5f, 0x73, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, - 0x0c, 0x62, 0x79, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x42, 0x0a, - 0x09, 0x62, 0x79, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x23, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x68, - 0x65, 0x61, 0x64, 0x65, 0x72, 0x48, 0x00, 0x52, 0x08, 0x62, 0x79, 0x48, 0x65, 0x61, 0x64, 0x65, - 0x72, 0x1a, 0x32, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, - 0x6f, 0x6e, 0x2a, 0x2f, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0f, - 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, - 0x08, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x47, 0x52, 0x50, - 0x43, 0x10, 0x02, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, - 0x77, 0x61, 0x79, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, - 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x31, 0x2e, 0x52, 0x65, 0x74, 0x72, 0x79, 0x52, 0x05, 0x72, 0x65, 0x74, 0x72, 0x79, 0x12, 0x45, + 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x29, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x2e, 0x4d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x0a, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x6c, 0x0a, 0x0a, 0x4d, 0x69, 0x64, 0x64, 0x6c, 0x65, + 0x77, 0x61, 0x72, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, + 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, + 0x69, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, + 0x69, 0x72, 0x65, 0x64, 0x22, 0xc6, 0x01, 0x0a, 0x07, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, + 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x77, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x06, 0x77, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x88, 0x01, 0x01, 0x12, 0x41, 0x0a, 0x0c, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x5f, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x67, 0x61, + 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x0b, 0x68, 0x65, 0x61, + 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6c, 0x73, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x74, 0x6c, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x74, 0x6c, + 0x73, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, 0x6c, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4e, 0x61, + 0x6d, 0x65, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x0d, 0x0a, + 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x22, 0xc4, 0x01, 0x0a, + 0x05, 0x52, 0x65, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, + 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, + 0x74, 0x73, 0x12, 0x41, 0x0a, 0x0f, 0x70, 0x65, 0x72, 0x5f, 0x74, 0x72, 0x79, 0x5f, 0x74, 0x69, + 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x70, 0x65, 0x72, 0x54, 0x72, 0x79, 0x54, 0x69, + 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, + 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x69, 0x65, + 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, + 0x69, 0x65, 0x73, 0x22, 0xb8, 0x01, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x26, 0x0a, 0x0e, 0x62, 0x79, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, + 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0c, 0x62, 0x79, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x42, 0x0a, 0x09, 0x62, 0x79, 0x5f, + 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x67, + 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, + 0x72, 0x48, 0x00, 0x52, 0x08, 0x62, 0x79, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x1a, 0x32, 0x0a, + 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2a, 0x2f, + 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, + 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x48, + 0x54, 0x54, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x47, 0x52, 0x50, 0x43, 0x10, 0x02, 0x42, + 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, + 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x63, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/gateway/config/v1/gateway.proto b/api/gateway/config/v1/gateway.proto index 5a015afa..bd67ce71 100644 --- a/api/gateway/config/v1/gateway.proto +++ b/api/gateway/config/v1/gateway.proto @@ -17,7 +17,7 @@ message Gateway { } message TLS { - bool verify = 1; + bool insecure = 1; string cacert = 2; string cert = 3; string key = 4; @@ -49,7 +49,8 @@ message Backend { string target = 1; optional int64 weight = 2; HealthCheck health_check = 3; - string tls = 4; + bool tls = 4; + string tls_config_name = 5; } enum Protocol { diff --git a/client/factory.go b/client/factory.go index bc4a7593..f45cb738 100644 --- a/client/factory.go +++ b/client/factory.go @@ -2,6 +2,8 @@ package client import ( "context" + "crypto/tls" + "crypto/x509" "fmt" "strconv" "strings" @@ -15,6 +17,8 @@ import ( "github.com/go-kratos/kratos/v2/selector/p2c" ) +var globalTLSClientConfigs = atomic.Pointer[map[string]*tls.Config]{} + // Factory is returns service client. type Factory func(*config.Endpoint) (Client, error) @@ -29,6 +33,31 @@ func WithPickerBuilder(in selector.Builder) Option { } } +func SetGlobalTLSClientConfigs(in map[string]*config.TLS) { + tlsConfigs := make(map[string]*tls.Config, len(in)) + for k, v := range in { + cfg := &tls.Config{ + InsecureSkipVerify: v.Insecure, + } + cert, err := tls.X509KeyPair([]byte(v.Cert), []byte(v.Key)) + if err != nil { + LOG.Warnf("failed to load tls cert: %q: %v", k, err) + continue + } + cfg.Certificates = []tls.Certificate{cert} + if v.Cacert != "" { + roots := x509.NewCertPool() + if ok := roots.AppendCertsFromPEM([]byte(v.Cacert)); !ok { + LOG.Warnf("failed to load tls cacert: %q", k) + continue + } + cfg.RootCAs = roots + } + tlsConfigs[k] = cfg + } + globalTLSClientConfigs.Store(&tlsConfigs) +} + // NewFactory new a client factory. func NewFactory(r registry.Discovery, opts ...Option) Factory { o := &options{ @@ -72,7 +101,7 @@ func (na *nodeApplier) apply(ctx context.Context) error { switch target.Scheme { case "direct": weighted := backend.Weight // weight is only valid for direct scheme - node := newNode(backend.Target, na.endpoint.Protocol, weighted, map[string]string{}, "", "") + node := newNode(backend.Target, na.endpoint.Protocol, weighted, map[string]string{}, "", "", WithTLS(backend.Tls), WithTLSConfigName(backend.TlsConfigName)) nodes = append(nodes, node) na.picker.Apply(nodes) case "discovery": @@ -116,7 +145,7 @@ func (na *nodeApplier) Callback(services []*registry.ServiceInstance) error { log.Errorf("failed to parse endpoint: %v/%s: %v", ser.Endpoints, scheme, err) continue } - node := newNode(addr, na.endpoint.Protocol, nodeWeight(ser), ser.Metadata, ser.Version, ser.Name) + node := newNode(addr, na.endpoint.Protocol, nodeWeight(ser), ser.Metadata, ser.Version, ser.Name, WithTLS(false)) nodes = append(nodes, node) } na.picker.Apply(nodes) diff --git a/client/node.go b/client/node.go index fc9c66a5..5555805f 100644 --- a/client/node.go +++ b/client/node.go @@ -20,7 +20,8 @@ import ( var _ selector.Node = &node{} var _globalClient = defaultClient() var _globalH2CClient = defaultH2CClient() -var _globalHTTPSClient = defaultHTTPSClient() +var _globalHTTPSClient = createHTTPSClient(nil) +var httpsClientStore = NewHTTPSClientStore() var _dialTimeout = 200 * time.Millisecond var followRedirect = false @@ -94,10 +95,10 @@ func defaultH2CClient() *http.Client { } } -func defaultHTTPSClient() *http.Client { +func createHTTPSClient(tlsConfig *tls.Config) *http.Client { tr := &http.Transport{ - // TLSClientConfig: , - Proxy: http.ProxyFromEnvironment, + TLSClientConfig: tlsConfig, + Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: _dialTimeout, KeepAlive: 30 * time.Second, @@ -117,28 +118,54 @@ func defaultHTTPSClient() *http.Client { } } -// func getTLSClient() *http.Client { -// return &http.Client{ -// CheckRedirect: defaultCheckRedirect, -// Transport: &http.Transport{ -// Proxy: http.ProxyFromEnvironment, -// // TLSClientConfig: , -// DialContext: (&net.Dialer{ -// Timeout: _dialTimeout, -// KeepAlive: 30 * time.Second, -// }).DialContext, -// MaxIdleConns: 10000, -// MaxIdleConnsPerHost: 1000, -// MaxConnsPerHost: 1000, -// DisableCompression: true, -// IdleConnTimeout: 90 * time.Second, -// TLSHandshakeTimeout: 10 * time.Second, -// ExpectContinueTimeout: 1 * time.Second, -// }, -// } -// } - -func newNode(addr string, protocol config.Protocol, weight *int64, md map[string]string, version string, name string) *node { +type HTTPSClientStore struct { + clients map[string]*http.Client +} + +func NewHTTPSClientStore() *HTTPSClientStore { + return &HTTPSClientStore{ + clients: make(map[string]*http.Client), + } +} + +func (s *HTTPSClientStore) GetClient(name string) *http.Client { + if name == "" { + return _globalClient + } + client, ok := s.clients[name] + if ok { + return client + } + globalConfigs := *globalTLSClientConfigs.Load() + tlsConfig, ok := globalConfigs[name] + if !ok { + LOG.Warnf("tls config not found for %s, using default instead", name) + return _globalHTTPSClient + } + client = createHTTPSClient(tlsConfig) + s.clients[name] = client + return client +} + +type NodeOptions struct { + TLS bool + TLSConfigName string +} +type NewNodeOption func(*NodeOptions) + +func WithTLS(in bool) NewNodeOption { + return func(o *NodeOptions) { + o.TLS = in + } +} + +func WithTLSConfigName(in string) NewNodeOption { + return func(o *NodeOptions) { + o.TLSConfigName = in + } +} + +func newNode(addr string, protocol config.Protocol, weight *int64, md map[string]string, version string, name string, opts ...NewNodeOption) *node { node := &node{ protocol: protocol, address: addr, @@ -151,7 +178,16 @@ func newNode(addr string, protocol config.Protocol, weight *int64, md map[string if protocol == config.Protocol_GRPC { node.client = _globalH2CClient } - + opt := &NodeOptions{} + for _, o := range opts { + o(opt) + } + if opt.TLS { + node.client = _globalHTTPSClient + if opt.TLSConfigName != "" { + node.client = httpsClientStore.GetClient(opt.TLSConfigName) + } + } return node } diff --git a/proxy/proxy.go b/proxy/proxy.go index 768d80d5..0d066f46 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -385,6 +385,7 @@ func closeOnError(closer io.Closer, err *error) { // Update updates service endpoint. func (p *Proxy) Update(c *config.Gateway) (retError error) { + client.SetGlobalTLSClientConfigs(c.TlsStore) router := mux.NewRouter(http.HandlerFunc(notFoundHandler), http.HandlerFunc(methodNotAllowedHandler)) for _, e := range c.Endpoints { handler, closer, err := p.buildEndpoint(e, c.Middlewares) From 49a5763231b0e5758a0cfb6684f6b56945d5412b Mon Sep 17 00:00:00 2001 From: realityone Date: Mon, 19 Feb 2024 14:39:38 +0800 Subject: [PATCH 03/11] builder context --- client/factory.go | 39 +++++++++++++-------- client/node.go | 16 ++++----- middleware/circuitbreaker/circuitbreaker.go | 10 +++--- proxy/proxy.go | 8 ++--- 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/client/factory.go b/client/factory.go index f45cb738..5cc51ac0 100644 --- a/client/factory.go +++ b/client/factory.go @@ -17,10 +17,13 @@ import ( "github.com/go-kratos/kratos/v2/selector/p2c" ) -var globalTLSClientConfigs = atomic.Pointer[map[string]*tls.Config]{} +type BuildContext struct { + TLSConfigs map[string]*tls.Config + TLSClientStore *HTTPSClientStore +} // Factory is returns service client. -type Factory func(*config.Endpoint) (Client, error) +type Factory func(*BuildContext, *config.Endpoint) (Client, error) type Option func(*options) type options struct { @@ -33,9 +36,13 @@ func WithPickerBuilder(in selector.Builder) Option { } } -func SetGlobalTLSClientConfigs(in map[string]*config.TLS) { - tlsConfigs := make(map[string]*tls.Config, len(in)) - for k, v := range in { +func EmptyBuildContext() *BuildContext { + return &BuildContext{} +} + +func NewBuildContext(cfg *config.Gateway) *BuildContext { + tlsConfigs := make(map[string]*tls.Config, len(cfg.TlsStore)) + for k, v := range cfg.TlsStore { cfg := &tls.Config{ InsecureSkipVerify: v.Insecure, } @@ -55,7 +62,10 @@ func SetGlobalTLSClientConfigs(in map[string]*config.TLS) { } tlsConfigs[k] = cfg } - globalTLSClientConfigs.Store(&tlsConfigs) + return &BuildContext{ + TLSConfigs: tlsConfigs, + TLSClientStore: NewHTTPSClientStore(tlsConfigs), + } } // NewFactory new a client factory. @@ -66,7 +76,7 @@ func NewFactory(r registry.Discovery, opts ...Option) Factory { for _, opt := range opts { opt(o) } - return func(endpoint *config.Endpoint) (Client, error) { + return func(builderCtx *BuildContext, endpoint *config.Endpoint) (Client, error) { picker := o.pickerBuilder.Build() ctx, cancel := context.WithCancel(context.Background()) applier := &nodeApplier{ @@ -84,11 +94,12 @@ func NewFactory(r registry.Discovery, opts ...Option) Factory { } type nodeApplier struct { - canceled int64 - cancel context.CancelFunc - endpoint *config.Endpoint - registry registry.Discovery - picker selector.Selector + canceled int64 + buildContext *BuildContext + cancel context.CancelFunc + endpoint *config.Endpoint + registry registry.Discovery + picker selector.Selector } func (na *nodeApplier) apply(ctx context.Context) error { @@ -101,7 +112,7 @@ func (na *nodeApplier) apply(ctx context.Context) error { switch target.Scheme { case "direct": weighted := backend.Weight // weight is only valid for direct scheme - node := newNode(backend.Target, na.endpoint.Protocol, weighted, map[string]string{}, "", "", WithTLS(backend.Tls), WithTLSConfigName(backend.TlsConfigName)) + node := newNode(na.buildContext, backend.Target, na.endpoint.Protocol, weighted, map[string]string{}, "", "", WithTLS(backend.Tls), WithTLSConfigName(backend.TlsConfigName)) nodes = append(nodes, node) na.picker.Apply(nodes) case "discovery": @@ -145,7 +156,7 @@ func (na *nodeApplier) Callback(services []*registry.ServiceInstance) error { log.Errorf("failed to parse endpoint: %v/%s: %v", ser.Endpoints, scheme, err) continue } - node := newNode(addr, na.endpoint.Protocol, nodeWeight(ser), ser.Metadata, ser.Version, ser.Name, WithTLS(false)) + node := newNode(na.buildContext, addr, na.endpoint.Protocol, nodeWeight(ser), ser.Metadata, ser.Version, ser.Name, WithTLS(false)) nodes = append(nodes, node) } na.picker.Apply(nodes) diff --git a/client/node.go b/client/node.go index 5555805f..e51b16ff 100644 --- a/client/node.go +++ b/client/node.go @@ -21,7 +21,6 @@ var _ selector.Node = &node{} var _globalClient = defaultClient() var _globalH2CClient = defaultH2CClient() var _globalHTTPSClient = createHTTPSClient(nil) -var httpsClientStore = NewHTTPSClientStore() var _dialTimeout = 200 * time.Millisecond var followRedirect = false @@ -119,12 +118,14 @@ func createHTTPSClient(tlsConfig *tls.Config) *http.Client { } type HTTPSClientStore struct { - clients map[string]*http.Client + clientConfigs map[string]*tls.Config + clients map[string]*http.Client } -func NewHTTPSClientStore() *HTTPSClientStore { +func NewHTTPSClientStore(clientConfigs map[string]*tls.Config) *HTTPSClientStore { return &HTTPSClientStore{ - clients: make(map[string]*http.Client), + clientConfigs: clientConfigs, + clients: make(map[string]*http.Client), } } @@ -136,8 +137,7 @@ func (s *HTTPSClientStore) GetClient(name string) *http.Client { if ok { return client } - globalConfigs := *globalTLSClientConfigs.Load() - tlsConfig, ok := globalConfigs[name] + tlsConfig, ok := s.clientConfigs[name] if !ok { LOG.Warnf("tls config not found for %s, using default instead", name) return _globalHTTPSClient @@ -165,7 +165,7 @@ func WithTLSConfigName(in string) NewNodeOption { } } -func newNode(addr string, protocol config.Protocol, weight *int64, md map[string]string, version string, name string, opts ...NewNodeOption) *node { +func newNode(ctx *BuildContext, addr string, protocol config.Protocol, weight *int64, md map[string]string, version string, name string, opts ...NewNodeOption) *node { node := &node{ protocol: protocol, address: addr, @@ -185,7 +185,7 @@ func newNode(addr string, protocol config.Protocol, weight *int64, md map[string if opt.TLS { node.client = _globalHTTPSClient if opt.TLSConfigName != "" { - node.client = httpsClientStore.GetClient(opt.TLSConfigName) + node.client = ctx.TLSClientStore.GetClient(opt.TLSConfigName) } } return node diff --git a/middleware/circuitbreaker/circuitbreaker.go b/middleware/circuitbreaker/circuitbreaker.go index 1789a6cf..6d61c629 100644 --- a/middleware/circuitbreaker/circuitbreaker.go +++ b/middleware/circuitbreaker/circuitbreaker.go @@ -22,7 +22,7 @@ import ( ) func Init(clientFactory client.Factory) { - breakerFactory := New(clientFactory) + breakerFactory := New(client.EmptyBuildContext(), clientFactory) middleware.RegisterV2("circuitbreaker", breakerFactory) prometheus.MustRegister(_metricDeniedTotal) } @@ -91,11 +91,11 @@ func makeBreakerTrigger(in *v1.CircuitBreaker) circuitbreaker.CircuitBreaker { } } -func makeOnBreakHandler(in *v1.CircuitBreaker, factory client.Factory) (http.RoundTripper, io.Closer, error) { +func makeOnBreakHandler(buildContext *client.BuildContext, in *v1.CircuitBreaker, factory client.Factory) (http.RoundTripper, io.Closer, error) { switch action := in.Action.(type) { case *v1.CircuitBreaker_BackupService: log.Infof("Making backup service as on break handler: %+v", action) - client, err := factory(action.BackupService.Endpoint) + client, err := factory(buildContext, action.BackupService.Endpoint) if err != nil { return nil, nil, err } @@ -138,7 +138,7 @@ func deniedRequestIncr(req *http.Request) { } } -func New(factory client.Factory) middleware.FactoryV2 { +func New(buildContext *client.BuildContext, factory client.Factory) middleware.FactoryV2 { return func(c *config.Middleware) (middleware.MiddlewareV2, error) { options := &v1.CircuitBreaker{} if c.Options != nil { @@ -147,7 +147,7 @@ func New(factory client.Factory) middleware.FactoryV2 { } } breaker := makeBreakerTrigger(options) - onBreakHandler, closer, err := makeOnBreakHandler(options, factory) + onBreakHandler, closer, err := makeOnBreakHandler(buildContext, options, factory) if err != nil { return nil, err } diff --git a/proxy/proxy.go b/proxy/proxy.go index 0d066f46..f94c24ae 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -212,8 +212,8 @@ func splitRetryMetricsHandler(e *config.Endpoint) (func(int), func(int, error)) return success, failed } -func (p *Proxy) buildEndpoint(e *config.Endpoint, ms []*config.Middleware) (_ http.Handler, _ io.Closer, retError error) { - client, err := p.clientFactory(e) +func (p *Proxy) buildEndpoint(buildCtx *client.BuildContext, e *config.Endpoint, ms []*config.Middleware) (_ http.Handler, _ io.Closer, retError error) { + client, err := p.clientFactory(buildCtx, e) if err != nil { return nil, nil, err } @@ -385,10 +385,10 @@ func closeOnError(closer io.Closer, err *error) { // Update updates service endpoint. func (p *Proxy) Update(c *config.Gateway) (retError error) { - client.SetGlobalTLSClientConfigs(c.TlsStore) + buildContext := client.NewBuildContext(c) router := mux.NewRouter(http.HandlerFunc(notFoundHandler), http.HandlerFunc(methodNotAllowedHandler)) for _, e := range c.Endpoints { - handler, closer, err := p.buildEndpoint(e, c.Middlewares) + handler, closer, err := p.buildEndpoint(buildContext, e, c.Middlewares) if err != nil { return err } From 1902b2a68b08bb9e7f90d4d550e72da31b3847d0 Mon Sep 17 00:00:00 2001 From: realityone Date: Mon, 19 Feb 2024 16:42:12 +0800 Subject: [PATCH 04/11] node tls tag --- client/client.go | 6 +++++- client/factory.go | 9 +++++---- client/node.go | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/client/client.go b/client/client.go index 572588f1..5f7fbe50 100644 --- a/client/client.go +++ b/client/client.go @@ -43,11 +43,15 @@ func (c *client) RoundTrip(req *http.Request) (resp *http.Response, err error) { addr := n.Address() reqOpt.Backends = append(reqOpt.Backends, addr) + backendNode := n.(*node) req.URL.Host = addr req.URL.Scheme = "http" + if backendNode.tls { + req.URL.Scheme = "https" + } req.RequestURI = "" startAt := time.Now() - resp, err = n.(*node).client.Do(req) + resp, err = backendNode.client.Do(req) reqOpt.UpstreamResponseTime = append(reqOpt.UpstreamResponseTime, time.Since(startAt).Seconds()) if err != nil { done(ctx, selector.DoneInfo{Err: err}) diff --git a/client/factory.go b/client/factory.go index 5cc51ac0..609994bd 100644 --- a/client/factory.go +++ b/client/factory.go @@ -80,10 +80,11 @@ func NewFactory(r registry.Discovery, opts ...Option) Factory { picker := o.pickerBuilder.Build() ctx, cancel := context.WithCancel(context.Background()) applier := &nodeApplier{ - cancel: cancel, - endpoint: endpoint, - registry: r, - picker: picker, + cancel: cancel, + endpoint: endpoint, + registry: r, + picker: picker, + buildContext: builderCtx, } if err := applier.apply(ctx); err != nil { return nil, err diff --git a/client/node.go b/client/node.go index e51b16ff..2e658ead 100644 --- a/client/node.go +++ b/client/node.go @@ -183,6 +183,7 @@ func newNode(ctx *BuildContext, addr string, protocol config.Protocol, weight *i o(opt) } if opt.TLS { + node.tls = true node.client = _globalHTTPSClient if opt.TLSConfigName != "" { node.client = ctx.TLSClientStore.GetClient(opt.TLSConfigName) @@ -200,6 +201,7 @@ type node struct { client *http.Client protocol config.Protocol + tls bool } func (n *node) Scheme() string { From efe1d17e7fcd0b9d74430765f44f02af346749ac Mon Sep 17 00:00:00 2001 From: realityone Date: Mon, 19 Feb 2024 17:20:27 +0800 Subject: [PATCH 05/11] backend metadata --- api/gateway/config/v1/gateway.pb.go | 132 ++++++++++++++++------------ api/gateway/config/v1/gateway.proto | 1 + client/factory.go | 2 +- 3 files changed, 77 insertions(+), 58 deletions(-) diff --git a/api/gateway/config/v1/gateway.pb.go b/api/gateway/config/v1/gateway.pb.go index 2e7fe507..9d2e0580 100644 --- a/api/gateway/config/v1/gateway.pb.go +++ b/api/gateway/config/v1/gateway.pb.go @@ -421,11 +421,12 @@ type Backend struct { // localhost // 127.0.0.1:8000 // discovery:///service_name - Target string `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"` - Weight *int64 `protobuf:"varint,2,opt,name=weight,proto3,oneof" json:"weight,omitempty"` - HealthCheck *HealthCheck `protobuf:"bytes,3,opt,name=health_check,json=healthCheck,proto3" json:"health_check,omitempty"` - Tls bool `protobuf:"varint,4,opt,name=tls,proto3" json:"tls,omitempty"` - TlsConfigName string `protobuf:"bytes,5,opt,name=tls_config_name,json=tlsConfigName,proto3" json:"tls_config_name,omitempty"` + Target string `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"` + Weight *int64 `protobuf:"varint,2,opt,name=weight,proto3,oneof" json:"weight,omitempty"` + HealthCheck *HealthCheck `protobuf:"bytes,3,opt,name=health_check,json=healthCheck,proto3" json:"health_check,omitempty"` + Tls bool `protobuf:"varint,4,opt,name=tls,proto3" json:"tls,omitempty"` + TlsConfigName string `protobuf:"bytes,5,opt,name=tls_config_name,json=tlsConfigName,proto3" json:"tls_config_name,omitempty"` + Metadata map[string]string `protobuf:"bytes,6,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *Backend) Reset() { @@ -495,6 +496,13 @@ func (x *Backend) GetTlsConfigName() string { return "" } +func (x *Backend) GetMetadata() map[string]string { + if x != nil { + return x.Metadata + } + return nil +} + type HealthCheck struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -701,7 +709,7 @@ type ConditionHeader struct { func (x *ConditionHeader) Reset() { *x = ConditionHeader{} if protoimpl.UnsafeEnabled { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[10] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -714,7 +722,7 @@ func (x *ConditionHeader) String() string { func (*ConditionHeader) ProtoMessage() {} func (x *ConditionHeader) ProtoReflect() protoreflect.Message { - mi := &file_gateway_config_v1_gateway_proto_msgTypes[10] + mi := &file_gateway_config_v1_gateway_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -822,7 +830,7 @@ var file_gateway_config_v1_gateway_proto_rawDesc = []byte{ 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, - 0x69, 0x72, 0x65, 0x64, 0x22, 0xc6, 0x01, 0x0a, 0x07, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, + 0x69, 0x72, 0x65, 0x64, 0x22, 0xc9, 0x02, 0x0a, 0x07, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x06, 0x77, 0x65, 0x69, 0x67, @@ -834,39 +842,47 @@ var file_gateway_config_v1_gateway_proto_rawDesc = []byte{ 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x74, 0x6c, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x74, 0x6c, 0x73, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, 0x6c, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4e, 0x61, - 0x6d, 0x65, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x0d, 0x0a, - 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x22, 0xc4, 0x01, 0x0a, - 0x05, 0x52, 0x65, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, - 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, - 0x74, 0x73, 0x12, 0x41, 0x0a, 0x0f, 0x70, 0x65, 0x72, 0x5f, 0x74, 0x72, 0x79, 0x5f, 0x74, 0x69, - 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x70, 0x65, 0x72, 0x54, 0x72, 0x79, 0x54, 0x69, - 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x61, 0x74, 0x65, - 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, - 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x69, 0x65, - 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, - 0x69, 0x65, 0x73, 0x22, 0xb8, 0x01, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, - 0x6e, 0x12, 0x26, 0x0a, 0x0e, 0x62, 0x79, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, - 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0c, 0x62, 0x79, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x42, 0x0a, 0x09, 0x62, 0x79, 0x5f, - 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x67, - 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, - 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, - 0x72, 0x48, 0x00, 0x52, 0x08, 0x62, 0x79, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x1a, 0x32, 0x0a, - 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x6d, 0x65, 0x12, 0x44, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x06, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, + 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, + 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, + 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2a, 0x2f, - 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, - 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x48, - 0x54, 0x54, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x47, 0x52, 0x50, 0x43, 0x10, 0x02, 0x42, - 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, - 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, - 0x61, 0x70, 0x69, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x63, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, + 0x22, 0x0d, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x22, + 0xc4, 0x01, 0x0a, 0x05, 0x52, 0x65, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x74, 0x74, + 0x65, 0x6d, 0x70, 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x74, 0x74, + 0x65, 0x6d, 0x70, 0x74, 0x73, 0x12, 0x41, 0x0a, 0x0f, 0x70, 0x65, 0x72, 0x5f, 0x74, 0x72, 0x79, + 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x70, 0x65, 0x72, 0x54, 0x72, + 0x79, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, + 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, + 0x74, 0x69, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x69, 0x6f, + 0x72, 0x69, 0x74, 0x69, 0x65, 0x73, 0x22, 0xb8, 0x01, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x64, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x0e, 0x62, 0x79, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0c, + 0x62, 0x79, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x42, 0x0a, 0x09, + 0x62, 0x79, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x23, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x68, 0x65, + 0x61, 0x64, 0x65, 0x72, 0x48, 0x00, 0x52, 0x08, 0x62, 0x79, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, + 0x1a, 0x32, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x2a, 0x2f, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0f, 0x0a, + 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, + 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x47, 0x52, 0x50, 0x43, + 0x10, 0x02, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, + 0x61, 0x79, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -882,7 +898,7 @@ func file_gateway_config_v1_gateway_proto_rawDescGZIP() []byte { } var file_gateway_config_v1_gateway_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_gateway_config_v1_gateway_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_gateway_config_v1_gateway_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_gateway_config_v1_gateway_proto_goTypes = []interface{}{ (Protocol)(0), // 0: gateway.config.v1.Protocol (*Gateway)(nil), // 1: gateway.config.v1.Gateway @@ -895,31 +911,33 @@ var file_gateway_config_v1_gateway_proto_goTypes = []interface{}{ (*Condition)(nil), // 8: gateway.config.v1.Condition nil, // 9: gateway.config.v1.Gateway.TlsStoreEntry nil, // 10: gateway.config.v1.Endpoint.MetadataEntry - (*ConditionHeader)(nil), // 11: gateway.config.v1.Condition.header - (*durationpb.Duration)(nil), // 12: google.protobuf.Duration - (*anypb.Any)(nil), // 13: google.protobuf.Any + nil, // 11: gateway.config.v1.Backend.MetadataEntry + (*ConditionHeader)(nil), // 12: gateway.config.v1.Condition.header + (*durationpb.Duration)(nil), // 13: google.protobuf.Duration + (*anypb.Any)(nil), // 14: google.protobuf.Any } var file_gateway_config_v1_gateway_proto_depIdxs = []int32{ 3, // 0: gateway.config.v1.Gateway.endpoints:type_name -> gateway.config.v1.Endpoint 4, // 1: gateway.config.v1.Gateway.middlewares:type_name -> gateway.config.v1.Middleware 9, // 2: gateway.config.v1.Gateway.tls_store:type_name -> gateway.config.v1.Gateway.TlsStoreEntry 0, // 3: gateway.config.v1.Endpoint.protocol:type_name -> gateway.config.v1.Protocol - 12, // 4: gateway.config.v1.Endpoint.timeout:type_name -> google.protobuf.Duration + 13, // 4: gateway.config.v1.Endpoint.timeout:type_name -> google.protobuf.Duration 4, // 5: gateway.config.v1.Endpoint.middlewares:type_name -> gateway.config.v1.Middleware 5, // 6: gateway.config.v1.Endpoint.backends:type_name -> gateway.config.v1.Backend 7, // 7: gateway.config.v1.Endpoint.retry:type_name -> gateway.config.v1.Retry 10, // 8: gateway.config.v1.Endpoint.metadata:type_name -> gateway.config.v1.Endpoint.MetadataEntry - 13, // 9: gateway.config.v1.Middleware.options:type_name -> google.protobuf.Any + 14, // 9: gateway.config.v1.Middleware.options:type_name -> google.protobuf.Any 6, // 10: gateway.config.v1.Backend.health_check:type_name -> gateway.config.v1.HealthCheck - 12, // 11: gateway.config.v1.Retry.per_try_timeout:type_name -> google.protobuf.Duration - 8, // 12: gateway.config.v1.Retry.conditions:type_name -> gateway.config.v1.Condition - 11, // 13: gateway.config.v1.Condition.by_header:type_name -> gateway.config.v1.Condition.header - 2, // 14: gateway.config.v1.Gateway.TlsStoreEntry.value:type_name -> gateway.config.v1.TLS - 15, // [15:15] is the sub-list for method output_type - 15, // [15:15] is the sub-list for method input_type - 15, // [15:15] is the sub-list for extension type_name - 15, // [15:15] is the sub-list for extension extendee - 0, // [0:15] is the sub-list for field type_name + 11, // 11: gateway.config.v1.Backend.metadata:type_name -> gateway.config.v1.Backend.MetadataEntry + 13, // 12: gateway.config.v1.Retry.per_try_timeout:type_name -> google.protobuf.Duration + 8, // 13: gateway.config.v1.Retry.conditions:type_name -> gateway.config.v1.Condition + 12, // 14: gateway.config.v1.Condition.by_header:type_name -> gateway.config.v1.Condition.header + 2, // 15: gateway.config.v1.Gateway.TlsStoreEntry.value:type_name -> gateway.config.v1.TLS + 16, // [16:16] is the sub-list for method output_type + 16, // [16:16] is the sub-list for method input_type + 16, // [16:16] is the sub-list for extension type_name + 16, // [16:16] is the sub-list for extension extendee + 0, // [0:16] is the sub-list for field type_name } func init() { file_gateway_config_v1_gateway_proto_init() } @@ -1024,7 +1042,7 @@ func file_gateway_config_v1_gateway_proto_init() { return nil } } - file_gateway_config_v1_gateway_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_gateway_config_v1_gateway_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ConditionHeader); i { case 0: return &v.state @@ -1048,7 +1066,7 @@ func file_gateway_config_v1_gateway_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_gateway_config_v1_gateway_proto_rawDesc, NumEnums: 1, - NumMessages: 11, + NumMessages: 12, NumExtensions: 0, NumServices: 0, }, diff --git a/api/gateway/config/v1/gateway.proto b/api/gateway/config/v1/gateway.proto index bd67ce71..51fbbbe1 100644 --- a/api/gateway/config/v1/gateway.proto +++ b/api/gateway/config/v1/gateway.proto @@ -51,6 +51,7 @@ message Backend { HealthCheck health_check = 3; bool tls = 4; string tls_config_name = 5; + map metadata = 6; } enum Protocol { diff --git a/client/factory.go b/client/factory.go index 609994bd..6823bda7 100644 --- a/client/factory.go +++ b/client/factory.go @@ -113,7 +113,7 @@ func (na *nodeApplier) apply(ctx context.Context) error { switch target.Scheme { case "direct": weighted := backend.Weight // weight is only valid for direct scheme - node := newNode(na.buildContext, backend.Target, na.endpoint.Protocol, weighted, map[string]string{}, "", "", WithTLS(backend.Tls), WithTLSConfigName(backend.TlsConfigName)) + node := newNode(na.buildContext, backend.Target, na.endpoint.Protocol, weighted, backend.Metadata, "", "", WithTLS(backend.Tls), WithTLSConfigName(backend.TlsConfigName)) nodes = append(nodes, node) na.picker.Apply(nodes) case "discovery": From 8d78c8866f37c5ce5a984842e7c107b718443373 Mon Sep 17 00:00:00 2001 From: realityone Date: Wed, 6 Mar 2024 11:25:01 +0800 Subject: [PATCH 06/11] test build --- proxy/proxy_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go index a9e451d3..1b32e12d 100644 --- a/proxy/proxy_test.go +++ b/proxy/proxy_test.go @@ -78,7 +78,7 @@ func TestProxy(t *testing.T) { }, } retryable := false - clientFactory := func(*config.Endpoint) (client.Client, error) { + clientFactory := func(*client.BuildContext, *config.Endpoint) (client.Client, error) { dummyClient := RoundTripperCloserFunc(func(req *http.Request) (*http.Response, error) { if retryable { retryable = false @@ -164,7 +164,7 @@ func TestRetryBreaker(t *testing.T) { responseSuccess := false retryToSuccess := false - clientFactory := func(*config.Endpoint) (client.Client, error) { + clientFactory := func(*client.BuildContext, *config.Endpoint) (client.Client, error) { dummyClient := RoundTripperCloserFunc(func(req *http.Request) (resp *http.Response, _ error) { opt, _ := middleware.FromRequestContext(req.Context()) defer func() { From 6eefebd86539d53abdaaea2bfa066443bec1e7fa Mon Sep 17 00:00:00 2001 From: realityone Date: Wed, 6 Mar 2024 11:27:33 +0800 Subject: [PATCH 07/11] remove test --- client/client_test.go | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 client/client_test.go diff --git a/client/client_test.go b/client/client_test.go deleted file mode 100644 index 9ba219a4..00000000 --- a/client/client_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package client - -import ( - "fmt" - "testing" -) - -func TestRequestHTTPS(t *testing.T) { - resp, err := _globalHTTPSClient.Get("https://www.bilibili.com") - if err != nil { - panic(err) - } - defer resp.Body.Close() - fmt.Println("RESP", resp.Proto, resp.Status, resp.StatusCode) -} From 25dfd7fa780f5bc6942129fb1d6ddf8149ec5cf5 Mon Sep 17 00:00:00 2001 From: realityone Date: Fri, 15 Mar 2024 16:21:12 +0800 Subject: [PATCH 08/11] enhance build context --- cmd/gateway/main.go | 9 ++++++--- middleware/circuitbreaker/circuitbreaker.go | 22 ++++++++++++++++----- proxy/proxy.go | 3 +-- proxy/proxy_test.go | 6 ++++-- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/cmd/gateway/main.go b/cmd/gateway/main.go index 617af77b..0d4db87b 100644 --- a/cmd/gateway/main.go +++ b/cmd/gateway/main.go @@ -97,7 +97,6 @@ func main() { if err != nil { log.Fatalf("failed to new proxy: %v", err) } - circuitbreaker.Init(clientFactory) ctx := context.Background() var ctrlLoader *configLoader.CtrlConfigLoader @@ -123,7 +122,9 @@ func main() { log.Fatalf("failed to load config: %v", err) } - if err := p.Update(bc); err != nil { + buildContext := client.NewBuildContext(bc) + circuitbreaker.Init(buildContext, clientFactory) + if err := p.Update(buildContext, bc); err != nil { log.Fatalf("failed to update service config: %v", err) } reloader := func() error { @@ -132,7 +133,9 @@ func main() { log.Errorf("failed to load config: %v", err) return err } - if err := p.Update(bc); err != nil { + buildContext := client.NewBuildContext(bc) + circuitbreaker.SetBuildContext(buildContext) + if err := p.Update(buildContext, bc); err != nil { log.Errorf("failed to update service config: %v", err) return err } diff --git a/middleware/circuitbreaker/circuitbreaker.go b/middleware/circuitbreaker/circuitbreaker.go index 6d61c629..bdf459f9 100644 --- a/middleware/circuitbreaker/circuitbreaker.go +++ b/middleware/circuitbreaker/circuitbreaker.go @@ -5,6 +5,7 @@ import ( "io" "net/http" "sync" + "sync/atomic" "time" "github.com/go-kratos/aegis/circuitbreaker" @@ -21,12 +22,23 @@ import ( "google.golang.org/protobuf/types/known/anypb" ) -func Init(clientFactory client.Factory) { - breakerFactory := New(client.EmptyBuildContext(), clientFactory) - middleware.RegisterV2("circuitbreaker", breakerFactory) +var clientBuildContext atomic.Pointer[client.BuildContext] + +func init() { + clientBuildContext.Store(client.EmptyBuildContext()) prometheus.MustRegister(_metricDeniedTotal) } +func Init(buildContext *client.BuildContext, clientFactory client.Factory) { + SetBuildContext(buildContext) + breakerFactory := New(clientFactory) + middleware.RegisterV2("circuitbreaker", breakerFactory) +} + +func SetBuildContext(buildContext *client.BuildContext) { + clientBuildContext.Store(buildContext) +} + var ( _metricDeniedTotal = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "go", @@ -138,7 +150,7 @@ func deniedRequestIncr(req *http.Request) { } } -func New(buildContext *client.BuildContext, factory client.Factory) middleware.FactoryV2 { +func New(factory client.Factory) middleware.FactoryV2 { return func(c *config.Middleware) (middleware.MiddlewareV2, error) { options := &v1.CircuitBreaker{} if c.Options != nil { @@ -147,7 +159,7 @@ func New(buildContext *client.BuildContext, factory client.Factory) middleware.F } } breaker := makeBreakerTrigger(options) - onBreakHandler, closer, err := makeOnBreakHandler(buildContext, options, factory) + onBreakHandler, closer, err := makeOnBreakHandler(clientBuildContext.Load(), options, factory) if err != nil { return nil, err } diff --git a/proxy/proxy.go b/proxy/proxy.go index 62c6aef5..057591ae 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -384,8 +384,7 @@ func closeOnError(closer io.Closer, err *error) { } // Update updates service endpoint. -func (p *Proxy) Update(c *config.Gateway) (retError error) { - buildContext := client.NewBuildContext(c) +func (p *Proxy) Update(buildContext *client.BuildContext, c *config.Gateway) (retError error) { router := mux.NewRouter(http.HandlerFunc(notFoundHandler), http.HandlerFunc(methodNotAllowedHandler)) for _, e := range c.Endpoints { handler, closer, err := p.buildEndpoint(buildContext, e, c.Middlewares) diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go index 1b32e12d..2cd15579 100644 --- a/proxy/proxy_test.go +++ b/proxy/proxy_test.go @@ -96,7 +96,8 @@ func TestProxy(t *testing.T) { if err != nil { t.Fatal(err) } - p.Update(c) + buildContext := client.NewBuildContext(c) + p.Update(buildContext, c) { b := []byte("notfound") r := httptest.NewRequest("GET", "/notfound", bytes.NewBuffer(b)) @@ -190,7 +191,8 @@ func TestRetryBreaker(t *testing.T) { if err != nil { t.Fatal(err) } - p.Update(c) + buildContext := client.NewBuildContext(c) + p.Update(buildContext, c) t.Run("retry-breaker", func(t *testing.T) { var lastResponse *responseWriter From 18ef199bf50cdcfb2628ab03f3bd6e6e23d0844b Mon Sep 17 00:00:00 2001 From: realityone Date: Wed, 20 Mar 2024 19:07:10 +0800 Subject: [PATCH 09/11] expose server_name --- api/gateway/config/v1/gateway.pb.go | 232 +++++++++++++++------------- api/gateway/config/v1/gateway.proto | 1 + client/factory.go | 1 + 3 files changed, 123 insertions(+), 111 deletions(-) diff --git a/api/gateway/config/v1/gateway.pb.go b/api/gateway/config/v1/gateway.pb.go index 5c24e95a..dcae948a 100644 --- a/api/gateway/config/v1/gateway.pb.go +++ b/api/gateway/config/v1/gateway.pb.go @@ -165,10 +165,11 @@ type TLS struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Insecure bool `protobuf:"varint,1,opt,name=insecure,proto3" json:"insecure,omitempty"` - Cacert string `protobuf:"bytes,2,opt,name=cacert,proto3" json:"cacert,omitempty"` - Cert string `protobuf:"bytes,3,opt,name=cert,proto3" json:"cert,omitempty"` - Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` + Insecure bool `protobuf:"varint,1,opt,name=insecure,proto3" json:"insecure,omitempty"` + Cacert string `protobuf:"bytes,2,opt,name=cacert,proto3" json:"cacert,omitempty"` + Cert string `protobuf:"bytes,3,opt,name=cert,proto3" json:"cert,omitempty"` + Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` + ServerName string `protobuf:"bytes,5,opt,name=server_name,json=serverName,proto3" json:"server_name,omitempty"` } func (x *TLS) Reset() { @@ -231,6 +232,13 @@ func (x *TLS) GetKey() string { return "" } +func (x *TLS) GetServerName() string { + if x != nil { + return x.ServerName + } + return "" +} + type PriorityConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -847,113 +855,115 @@ var file_gateway_config_v1_gateway_proto_rawDesc = []byte{ 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2c, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x4c, 0x53, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x5f, 0x0a, 0x03, 0x54, - 0x4c, 0x53, 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x12, 0x16, - 0x0a, 0x06, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x65, 0x72, 0x74, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x65, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, - 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x79, 0x0a, 0x0e, - 0x50, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, - 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x39, 0x0a, 0x09, - 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x1b, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x09, 0x65, 0x6e, - 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x22, 0x87, 0x04, 0x0a, 0x08, 0x45, 0x6e, 0x64, 0x70, - 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, - 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, - 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, - 0x6f, 0x6e, 0x12, 0x37, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, - 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, - 0x6c, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x33, 0x0a, 0x07, 0x74, - 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, - 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, - 0x12, 0x3f, 0x0a, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x73, 0x18, - 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, - 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x69, 0x64, 0x64, 0x6c, 0x65, - 0x77, 0x61, 0x72, 0x65, 0x52, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, - 0x73, 0x12, 0x36, 0x0a, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x07, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x52, - 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x2e, 0x0a, 0x05, 0x72, 0x65, 0x74, - 0x72, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, - 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x74, - 0x72, 0x79, 0x52, 0x05, 0x72, 0x65, 0x74, 0x72, 0x79, 0x12, 0x45, 0x0a, 0x08, 0x6d, 0x65, 0x74, - 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x67, 0x61, - 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, - 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, - 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, - 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, - 0x68, 0x6f, 0x73, 0x74, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, - 0x01, 0x22, 0x6c, 0x0a, 0x0a, 0x4d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x12, - 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, - 0xc9, 0x02, 0x0a, 0x07, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x74, - 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x61, 0x72, - 0x67, 0x65, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x88, 0x01, 0x01, - 0x12, 0x41, 0x0a, 0x0c, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x5f, 0x63, 0x68, 0x65, 0x63, 0x6b, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, - 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, - 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x0b, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, - 0x65, 0x63, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x03, 0x74, 0x6c, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x74, 0x6c, 0x73, 0x5f, 0x63, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, - 0x74, 0x6c, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x44, 0x0a, - 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x28, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, - 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, - 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x0d, 0x0a, 0x0b, 0x48, - 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x22, 0xc4, 0x01, 0x0a, 0x05, 0x52, - 0x65, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x73, - 0x12, 0x41, 0x0a, 0x0f, 0x70, 0x65, 0x72, 0x5f, 0x74, 0x72, 0x79, 0x5f, 0x74, 0x69, 0x6d, 0x65, - 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x70, 0x65, 0x72, 0x54, 0x72, 0x79, 0x54, 0x69, 0x6d, 0x65, - 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, - 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x64, - 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x69, 0x65, 0x73, 0x18, - 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x69, 0x65, - 0x73, 0x22, 0xb8, 0x01, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, - 0x26, 0x0a, 0x0e, 0x62, 0x79, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0c, 0x62, 0x79, 0x53, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x42, 0x0a, 0x09, 0x62, 0x79, 0x5f, 0x68, 0x65, - 0x61, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x67, 0x61, 0x74, - 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, - 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x48, - 0x00, 0x52, 0x08, 0x62, 0x79, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x1a, 0x32, 0x0a, 0x06, 0x68, - 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, - 0x0b, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2a, 0x2f, 0x0a, 0x08, - 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, - 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x48, 0x54, 0x54, - 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x47, 0x52, 0x50, 0x43, 0x10, 0x02, 0x42, 0x34, 0x5a, - 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, - 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x61, 0x70, - 0x69, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x80, 0x01, 0x0a, 0x03, + 0x54, 0x4c, 0x53, 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x65, 0x72, 0x74, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x65, 0x72, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1f, 0x0a, + 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x79, + 0x0a, 0x0e, 0x50, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x39, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x1b, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x09, + 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x22, 0x87, 0x04, 0x0a, 0x08, 0x45, 0x6e, + 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, + 0x74, 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x37, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, + 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x63, 0x6f, 0x6c, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x33, 0x0a, + 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, + 0x75, 0x74, 0x12, 0x3f, 0x0a, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, + 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, + 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x69, 0x64, 0x64, + 0x6c, 0x65, 0x77, 0x61, 0x72, 0x65, 0x52, 0x0b, 0x6d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, + 0x72, 0x65, 0x73, 0x12, 0x36, 0x0a, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x18, + 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, + 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, + 0x64, 0x52, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x2e, 0x0a, 0x05, 0x72, + 0x65, 0x74, 0x72, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x67, 0x61, 0x74, + 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x52, + 0x65, 0x74, 0x72, 0x79, 0x52, 0x05, 0x72, 0x65, 0x74, 0x72, 0x79, 0x12, 0x45, 0x0a, 0x08, 0x6d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, + 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, + 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, + 0x02, 0x38, 0x01, 0x22, 0x6c, 0x0a, 0x0a, 0x4d, 0x69, 0x64, 0x64, 0x6c, 0x65, 0x77, 0x61, 0x72, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x6f, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, + 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, + 0x64, 0x22, 0xc9, 0x02, 0x0a, 0x07, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x12, 0x16, 0x0a, + 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, + 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x06, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x88, + 0x01, 0x01, 0x12, 0x41, 0x0a, 0x0c, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x5f, 0x63, 0x68, 0x65, + 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, + 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, 0x61, + 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x0b, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x03, 0x74, 0x6c, 0x73, 0x12, 0x26, 0x0a, 0x0f, 0x74, 0x6c, 0x73, 0x5f, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0d, 0x74, 0x6c, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x4e, 0x61, 0x6d, 0x65, 0x12, + 0x44, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x28, 0x2e, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x2e, 0x4d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, + 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x0d, 0x0a, + 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x22, 0xc4, 0x01, 0x0a, + 0x05, 0x52, 0x65, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, + 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x74, 0x74, 0x65, 0x6d, 0x70, + 0x74, 0x73, 0x12, 0x41, 0x0a, 0x0f, 0x70, 0x65, 0x72, 0x5f, 0x74, 0x72, 0x79, 0x5f, 0x74, 0x69, + 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0d, 0x70, 0x65, 0x72, 0x54, 0x72, 0x79, 0x54, 0x69, + 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, + 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x69, 0x65, + 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, + 0x69, 0x65, 0x73, 0x22, 0xb8, 0x01, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x26, 0x0a, 0x0e, 0x62, 0x79, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, + 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0c, 0x62, 0x79, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x42, 0x0a, 0x09, 0x62, 0x79, 0x5f, + 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x67, + 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, + 0x2e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, + 0x72, 0x48, 0x00, 0x52, 0x08, 0x62, 0x79, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x1a, 0x32, 0x0a, + 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2a, 0x2f, + 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, + 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x48, + 0x54, 0x54, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x47, 0x52, 0x50, 0x43, 0x10, 0x02, 0x42, + 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, + 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x2f, 0x63, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/gateway/config/v1/gateway.proto b/api/gateway/config/v1/gateway.proto index 475de3d2..13abe694 100644 --- a/api/gateway/config/v1/gateway.proto +++ b/api/gateway/config/v1/gateway.proto @@ -21,6 +21,7 @@ message TLS { string cacert = 2; string cert = 3; string key = 4; + string server_name = 5; } message PriorityConfig { diff --git a/client/factory.go b/client/factory.go index 6823bda7..791ba214 100644 --- a/client/factory.go +++ b/client/factory.go @@ -45,6 +45,7 @@ func NewBuildContext(cfg *config.Gateway) *BuildContext { for k, v := range cfg.TlsStore { cfg := &tls.Config{ InsecureSkipVerify: v.Insecure, + ServerName: v.ServerName, } cert, err := tls.X509KeyPair([]byte(v.Cert), []byte(v.Key)) if err != nil { From 07d065a444604d7ad03fba37fefe464ebd32ad00 Mon Sep 17 00:00:00 2001 From: realityone Date: Tue, 26 Mar 2024 20:16:01 +0800 Subject: [PATCH 10/11] fill https request host if host is none --- client/client.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/client.go b/client/client.go index 5f7fbe50..d232c90e 100644 --- a/client/client.go +++ b/client/client.go @@ -48,6 +48,9 @@ func (c *client) RoundTrip(req *http.Request) (resp *http.Response, err error) { req.URL.Scheme = "http" if backendNode.tls { req.URL.Scheme = "https" + if req.Host == "" { + req.Host = addr + } } req.RequestURI = "" startAt := time.Now() From 52ebbc7720a805c173fe5bda9d7320c54ccfb545 Mon Sep 17 00:00:00 2001 From: realityone Date: Tue, 26 Mar 2024 20:25:32 +0800 Subject: [PATCH 11/11] using addr directly when https --- client/client.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/client.go b/client/client.go index d232c90e..4d7abc24 100644 --- a/client/client.go +++ b/client/client.go @@ -48,9 +48,7 @@ func (c *client) RoundTrip(req *http.Request) (resp *http.Response, err error) { req.URL.Scheme = "http" if backendNode.tls { req.URL.Scheme = "https" - if req.Host == "" { - req.Host = addr - } + req.Host = addr } req.RequestURI = "" startAt := time.Now()