From 1af00fadc3ecf8d685a38e4c18284a97b037cd5f Mon Sep 17 00:00:00 2001 From: godcong Date: Mon, 11 Nov 2024 16:41:19 +0800 Subject: [PATCH] refactor(config): import internal config package - Update import path for internal config package - Add new constants for custom source config --- runtime/config/config.go | 5 +- runtime/internal/config/v1/source.pb.go | 181 ++++++++++++------ .../internal/config/v1/source.pb.validate.go | 131 +++++++++++++ runtime/proto/config/v1/source.proto | 8 +- runtime/proto/example/example.proto | 13 ++ 5 files changed, 273 insertions(+), 65 deletions(-) create mode 100644 runtime/proto/example/example.proto diff --git a/runtime/config/config.go b/runtime/config/config.go index f0a8085..f0a26cd 100644 --- a/runtime/config/config.go +++ b/runtime/config/config.go @@ -3,7 +3,7 @@ package config import ( kratosconfig "github.com/go-kratos/kratos/v2/config" - config "github.com/origadmin/toolkits/runtime/internal/config/v1" + "github.com/origadmin/toolkits/runtime/internal/config/v1" ) type ( @@ -116,6 +116,9 @@ type ( SourceConfig_ETCD = config.SourceConfig_ETCD SourceConfig_ETCDMultiError = config.SourceConfig_ETCDMultiError SourceConfig_ETCDValidationError = config.SourceConfig_ETCDValidationError + SourceConfig_Custom = config.SourceConfig_Custom + SourceConfig_CustomMultiError = config.SourceConfig_CustomMultiError + SourceConfig_CustomValidationError = config.SourceConfig_CustomValidationError SourceConfig_File = config.SourceConfig_File SourceConfig_FileMultiError = config.SourceConfig_FileMultiError SourceConfig_FileValidationError = config.SourceConfig_FileValidationError diff --git a/runtime/internal/config/v1/source.pb.go b/runtime/internal/config/v1/source.pb.go index 4823eda..2b27fcb 100644 --- a/runtime/internal/config/v1/source.pb.go +++ b/runtime/internal/config/v1/source.pb.go @@ -10,6 +10,7 @@ import ( _ "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + anypb "google.golang.org/protobuf/types/known/anypb" reflect "reflect" sync "sync" ) @@ -293,6 +294,51 @@ func (x *SourceConfig_ETCD) GetEndpoints() []string { return nil } +type SourceConfig_Custom struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Config *anypb.Any `protobuf:"bytes,1,opt,name=config,proto3" json:"config,omitempty"` +} + +func (x *SourceConfig_Custom) Reset() { + *x = SourceConfig_Custom{} + mi := &file_config_v1_source_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SourceConfig_Custom) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SourceConfig_Custom) ProtoMessage() {} + +func (x *SourceConfig_Custom) ProtoReflect() protoreflect.Message { + mi := &file_config_v1_source_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SourceConfig_Custom.ProtoReflect.Descriptor instead. +func (*SourceConfig_Custom) Descriptor() ([]byte, []int) { + return file_config_v1_source_proto_rawDescGZIP(), []int{0, 3} +} + +func (x *SourceConfig_Custom) GetConfig() *anypb.Any { + if x != nil { + return x.Config + } + return nil +} + var File_config_v1_source_proto protoreflect.FileDescriptor var file_config_v1_source_proto_rawDesc = []byte{ @@ -300,60 +346,66 @@ var file_config_v1_source_proto_rawDesc = []byte{ 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0xb9, 0x05, 0x0a, 0x0c, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x12, 0x51, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, - 0x3d, 0xba, 0x48, 0x3a, 0x72, 0x38, 0x52, 0x04, 0x6e, 0x6f, 0x6e, 0x65, 0x52, 0x06, 0x63, 0x6f, - 0x6e, 0x73, 0x75, 0x6c, 0x52, 0x04, 0x65, 0x74, 0x63, 0x64, 0x52, 0x05, 0x6e, 0x61, 0x63, 0x6f, - 0x73, 0x52, 0x06, 0x61, 0x70, 0x6f, 0x6c, 0x6c, 0x6f, 0x52, 0x0a, 0x6b, 0x75, 0x62, 0x65, 0x72, - 0x6e, 0x65, 0x74, 0x65, 0x73, 0x52, 0x07, 0x70, 0x6f, 0x6c, 0x61, 0x72, 0x69, 0x73, 0x52, 0x04, - 0x74, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x35, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, - 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, - 0x46, 0x69, 0x6c, 0x65, 0x48, 0x00, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x88, 0x01, 0x01, 0x12, - 0x3b, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x1e, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, - 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x48, - 0x01, 0x52, 0x06, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x88, 0x01, 0x01, 0x12, 0x35, 0x0a, 0x04, - 0x65, 0x74, 0x63, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x63, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x2e, 0x45, 0x54, 0x43, 0x44, 0x48, 0x02, 0x52, 0x04, 0x65, 0x74, 0x63, 0x64, - 0x88, 0x01, 0x01, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x73, 0x18, 0x06, - 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x73, 0x12, 0x22, 0x0a, - 0x0c, 0x65, 0x6e, 0x76, 0x5f, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x65, 0x73, 0x18, 0x08, 0x20, - 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x6e, 0x76, 0x5f, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x65, - 0x73, 0x12, 0x40, 0x0a, 0x08, 0x65, 0x6e, 0x76, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x18, 0x07, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, - 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x45, 0x6e, 0x76, - 0x41, 0x72, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x65, 0x6e, 0x76, 0x5f, 0x61, - 0x72, 0x67, 0x73, 0x1a, 0x32, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, - 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, - 0x16, 0x0a, 0x06, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x06, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x1a, 0x64, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x73, 0x75, - 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, - 0x63, 0x68, 0x65, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x63, 0x68, - 0x65, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, - 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x1a, 0x24, 0x0a, - 0x04, 0x45, 0x54, 0x43, 0x44, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, - 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, - 0x6e, 0x74, 0x73, 0x1a, 0x3a, 0x0a, 0x0c, 0x45, 0x6e, 0x76, 0x41, 0x72, 0x67, 0x73, 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, - 0x07, 0x0a, 0x05, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x63, 0x6f, 0x6e, - 0x73, 0x75, 0x6c, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x65, 0x74, 0x63, 0x64, 0x42, 0x96, 0x01, 0x0a, - 0x0d, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x0b, - 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x72, 0x69, 0x67, 0x61, 0x64, - 0x6d, 0x69, 0x6e, 0x2f, 0x74, 0x6f, 0x6f, 0x6c, 0x6b, 0x69, 0x74, 0x73, 0x2f, 0x72, 0x75, 0x6e, - 0x74, 0x69, 0x6d, 0x65, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x3b, 0x63, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0xa2, 0x02, 0x03, 0x43, 0x58, 0x58, 0xaa, 0x02, 0x09, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x09, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5c, 0x56, 0x31, - 0xe2, 0x02, 0x15, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, - 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0a, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xff, 0x05, 0x0a, 0x0c, + 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x5f, 0x0a, 0x04, + 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x4b, 0xba, 0x48, 0x48, 0x72, + 0x46, 0x52, 0x04, 0x6e, 0x6f, 0x6e, 0x65, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x06, 0x63, + 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x52, 0x04, 0x65, 0x74, 0x63, 0x64, 0x52, 0x05, 0x6e, 0x61, 0x63, + 0x6f, 0x73, 0x52, 0x06, 0x61, 0x70, 0x6f, 0x6c, 0x6c, 0x6f, 0x52, 0x0a, 0x6b, 0x75, 0x62, 0x65, + 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x52, 0x07, 0x70, 0x6f, 0x6c, 0x61, 0x72, 0x69, 0x73, 0x52, + 0x06, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x12, 0x35, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x1c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, + 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x48, 0x00, 0x52, + 0x04, 0x66, 0x69, 0x6c, 0x65, 0x88, 0x01, 0x01, 0x12, 0x3b, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x73, + 0x75, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x48, 0x01, 0x52, 0x06, 0x63, 0x6f, 0x6e, 0x73, + 0x75, 0x6c, 0x88, 0x01, 0x01, 0x12, 0x35, 0x0a, 0x04, 0x65, 0x74, 0x63, 0x64, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x45, 0x54, 0x43, + 0x44, 0x48, 0x02, 0x52, 0x04, 0x65, 0x74, 0x63, 0x64, 0x88, 0x01, 0x01, 0x12, 0x18, 0x0a, 0x07, + 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x66, + 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x73, 0x12, 0x22, 0x0a, 0x0c, 0x65, 0x6e, 0x76, 0x5f, 0x70, 0x72, + 0x65, 0x66, 0x69, 0x78, 0x65, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x6e, + 0x76, 0x5f, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x65, 0x73, 0x12, 0x40, 0x0a, 0x08, 0x65, 0x6e, + 0x76, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x45, 0x6e, 0x76, 0x41, 0x72, 0x67, 0x73, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x52, 0x08, 0x65, 0x6e, 0x76, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x1a, 0x32, 0x0a, 0x04, + 0x46, 0x69, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x6f, 0x72, 0x6d, + 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, + 0x1a, 0x64, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x1a, 0x24, 0x0a, 0x04, 0x45, 0x54, 0x43, 0x44, 0x12, 0x1c, + 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x09, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x1a, 0x36, 0x0a, 0x06, + 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x12, 0x2c, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x18, 0x01, 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, 0x06, 0x63, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x1a, 0x3a, 0x0a, 0x0c, 0x45, 0x6e, 0x76, 0x41, 0x72, 0x67, 0x73, 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, 0x07, 0x0a, 0x05, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x63, 0x6f, + 0x6e, 0x73, 0x75, 0x6c, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x65, 0x74, 0x63, 0x64, 0x42, 0x96, 0x01, + 0x0a, 0x0d, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x42, + 0x0b, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x72, 0x69, 0x67, 0x61, + 0x64, 0x6d, 0x69, 0x6e, 0x2f, 0x74, 0x6f, 0x6f, 0x6c, 0x6b, 0x69, 0x74, 0x73, 0x2f, 0x72, 0x75, + 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x3b, 0x63, 0x6f, 0x6e, + 0x66, 0x69, 0x67, 0xa2, 0x02, 0x03, 0x43, 0x58, 0x58, 0xaa, 0x02, 0x09, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x09, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5c, 0x56, + 0x31, 0xe2, 0x02, 0x15, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, + 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0a, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -368,24 +420,27 @@ func file_config_v1_source_proto_rawDescGZIP() []byte { return file_config_v1_source_proto_rawDescData } -var file_config_v1_source_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_config_v1_source_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_config_v1_source_proto_goTypes = []any{ (*SourceConfig)(nil), // 0: config.v1.SourceConfig (*SourceConfig_File)(nil), // 1: config.v1.SourceConfig.File (*SourceConfig_Consul)(nil), // 2: config.v1.SourceConfig.Consul (*SourceConfig_ETCD)(nil), // 3: config.v1.SourceConfig.ETCD - nil, // 4: config.v1.SourceConfig.EnvArgsEntry + (*SourceConfig_Custom)(nil), // 4: config.v1.SourceConfig.Custom + nil, // 5: config.v1.SourceConfig.EnvArgsEntry + (*anypb.Any)(nil), // 6: google.protobuf.Any } var file_config_v1_source_proto_depIdxs = []int32{ 1, // 0: config.v1.SourceConfig.file:type_name -> config.v1.SourceConfig.File 2, // 1: config.v1.SourceConfig.consul:type_name -> config.v1.SourceConfig.Consul 3, // 2: config.v1.SourceConfig.etcd:type_name -> config.v1.SourceConfig.ETCD - 4, // 3: config.v1.SourceConfig.env_args:type_name -> config.v1.SourceConfig.EnvArgsEntry - 4, // [4:4] is the sub-list for method output_type - 4, // [4:4] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 5, // 3: config.v1.SourceConfig.env_args:type_name -> config.v1.SourceConfig.EnvArgsEntry + 6, // 4: config.v1.SourceConfig.Custom.config:type_name -> google.protobuf.Any + 5, // [5:5] is the sub-list for method output_type + 5, // [5:5] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_config_v1_source_proto_init() } @@ -400,7 +455,7 @@ func file_config_v1_source_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_config_v1_source_proto_rawDesc, NumEnums: 0, - NumMessages: 5, + NumMessages: 6, NumExtensions: 0, NumServices: 0, }, diff --git a/runtime/internal/config/v1/source.pb.validate.go b/runtime/internal/config/v1/source.pb.validate.go index ce72ac0..e624923 100644 --- a/runtime/internal/config/v1/source.pb.validate.go +++ b/runtime/internal/config/v1/source.pb.validate.go @@ -556,3 +556,134 @@ var _ interface { Cause() error ErrorName() string } = SourceConfig_ETCDValidationError{} + +// Validate checks the field values on SourceConfig_Custom with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *SourceConfig_Custom) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on SourceConfig_Custom with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// SourceConfig_CustomMultiError, or nil if none found. +func (m *SourceConfig_Custom) ValidateAll() error { + return m.validate(true) +} + +func (m *SourceConfig_Custom) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetConfig()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, SourceConfig_CustomValidationError{ + field: "Config", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, SourceConfig_CustomValidationError{ + field: "Config", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetConfig()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return SourceConfig_CustomValidationError{ + field: "Config", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return SourceConfig_CustomMultiError(errors) + } + + return nil +} + +// SourceConfig_CustomMultiError is an error wrapping multiple validation +// errors returned by SourceConfig_Custom.ValidateAll() if the designated +// constraints aren't met. +type SourceConfig_CustomMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m SourceConfig_CustomMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m SourceConfig_CustomMultiError) AllErrors() []error { return m } + +// SourceConfig_CustomValidationError is the validation error returned by +// SourceConfig_Custom.Validate if the designated constraints aren't met. +type SourceConfig_CustomValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e SourceConfig_CustomValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e SourceConfig_CustomValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e SourceConfig_CustomValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e SourceConfig_CustomValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e SourceConfig_CustomValidationError) ErrorName() string { + return "SourceConfig_CustomValidationError" +} + +// Error satisfies the builtin error interface +func (e SourceConfig_CustomValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sSourceConfig_Custom.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = SourceConfig_CustomValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = SourceConfig_CustomValidationError{} diff --git a/runtime/proto/config/v1/source.proto b/runtime/proto/config/v1/source.proto index 51581de..d53f41a 100644 --- a/runtime/proto/config/v1/source.proto +++ b/runtime/proto/config/v1/source.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package config.v1; import "buf/validate/validate.proto"; +import "google/protobuf/any.proto"; option go_package = "github.com/origadmin/toolkits/runtime/config;config"; @@ -30,7 +31,12 @@ message SourceConfig { message ETCD { repeated string endpoints = 1 [json_name = "endpoints"]; } - string type = 1 [(buf.validate.field).string = {in: ["none", "consul", "etcd", "nacos", "apollo", "kubernetes", "polaris"]}]; // Type + + message Custom { + google.protobuf.Any config = 1 [json_name = "config"]; + } + + string type = 1 [(buf.validate.field).string = {in: ["none", "file", "consul", "etcd", "nacos", "apollo", "kubernetes", "polaris", "custom"]}]; // Type string name = 2 [json_name = "name"]; // Name optional File file = 3 [json_name = "file"]; optional Consul consul = 4 [json_name = "consul"]; // Consul diff --git a/runtime/proto/example/example.proto b/runtime/proto/example/example.proto new file mode 100644 index 0000000..5311ce4 --- /dev/null +++ b/runtime/proto/example/example.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package example; + +import "config/v1/cors.proto"; + +option go_package = "github.com/origadmin/toolkits/runtime/example;example"; + +message Example { + string name = 1; + string value = 2; + config.v1.CorsConfig cors = 3; +} \ No newline at end of file