diff --git a/cmd/protoc-gen-go-gins/gins.go b/cmd/protoc-gen-go-gins/gins.go index 0683000..33f0b00 100644 --- a/cmd/protoc-gen-go-gins/gins.go +++ b/cmd/protoc-gen-go-gins/gins.go @@ -18,7 +18,7 @@ import ( const ( contextPackage = protogen.GoImportPath("context") ginPackage = protogen.GoImportPath("github.com/gin-gonic/gin") - ginsPackage = protogen.GoImportPath("github.com/origadmin/toolkits/runtime/kratos/transport/gins") + ginsPackage = protogen.GoImportPath("github.com/origadmin/toolkits/runtime/transport/gins") bindingPackage = protogen.GoImportPath("github.com/go-kratos/kratos/v2/transport/http/binding") //transportHTTPPackage = protogen.GoImportPath("github.com/go-kratos/kratos/v2/transport/http") ) diff --git a/examples/buf.lock b/examples/buf.lock index 077deea..b2af281 100644 --- a/examples/buf.lock +++ b/examples/buf.lock @@ -1,6 +1,12 @@ # Generated by buf. DO NOT EDIT. version: v2 deps: + - name: buf.build/bufbuild/protovalidate + commit: 5a7b106cbb87462d9a8c9ffecdbd2e38 + digest: b5:0f2dc6c9453e9cc9e9f36807aaa5f94022e837d91fef4dcaeed79a35c0843cc64eba28ff077aab24da3b2cb12639ad256246f9f9a36c033b99d5754b19996b7e - name: buf.build/googleapis/googleapis - commit: f52d4f76a8434cc5966798b1d3b4f110 - digest: b5:5e634ff0ee118aea188b3e9c13ad7d285a192ef6c591bc20ff5a3360438d6ca310cfe9d663b20d60e1daa21789add35b919eac84e8e94a4d576e83a50dd2d62c + commit: 553fd4b4b3a640be9b69a3fa0c17b383 + digest: b5:9e7cb39758f3487f0751765227dc0b9f0ef7a401ab37fa2e97c363446810f4bd0dca1f46dbb793a12d98c019f4028e48d0831b5cb3f09190f068ec1866c69c1d + - name: buf.build/origadmin/runtime + commit: 157d05fd7b25402aa7aa58ed28f7a3b6 + digest: b5:333b207fe1af60e28ba0db9aac8526638fcec6baab132dd9e3ce1603078836f245946d544dca965cb839864172024db3dbfa4d013d0b10e26361df36a2e2803f diff --git a/examples/buf.yaml b/examples/buf.yaml index 471dfd9..87db757 100644 --- a/examples/buf.yaml +++ b/examples/buf.yaml @@ -13,4 +13,5 @@ breaking: - FILE deps: - buf.build/googleapis/googleapis + - buf.build/origadmin/runtime # - buf.build/envoyproxy/protoc-gen-validate diff --git a/examples/proto/helloworld/v1/helloworld.proto b/examples/proto/helloworld/v1/helloworld.proto index 4af3213..b61a067 100644 --- a/examples/proto/helloworld/v1/helloworld.proto +++ b/examples/proto/helloworld/v1/helloworld.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package helloworld.v1; +import "config/v1/cors.proto"; import "google/api/annotations.proto"; option go_package = "github.com/origadmin/toolkits/examples/services/helloworld/v1;helloworld"; @@ -29,3 +30,7 @@ message SayHelloRequest { message SayHelloResponse { string message = 1; } + +message ExampleCors { + config.v1.CorsConfig cors = 1; +} \ No newline at end of file diff --git a/examples/services/helloworld/v1/helloworld.pb.go b/examples/services/helloworld/v1/helloworld.pb.go index 907c5cf..73fccd3 100644 --- a/examples/services/helloworld/v1/helloworld.pb.go +++ b/examples/services/helloworld/v1/helloworld.pb.go @@ -7,6 +7,7 @@ package helloworld import ( + config "github.com/origadmin/toolkits/runtime/config" _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -113,20 +114,70 @@ func (x *SayHelloResponse) GetMessage() string { return "" } +type ExampleCors struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Cors *config.CorsConfig `protobuf:"bytes,1,opt,name=cors,proto3" json:"cors,omitempty"` +} + +func (x *ExampleCors) Reset() { + *x = ExampleCors{} + mi := &file_helloworld_v1_helloworld_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ExampleCors) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ExampleCors) ProtoMessage() {} + +func (x *ExampleCors) ProtoReflect() protoreflect.Message { + mi := &file_helloworld_v1_helloworld_proto_msgTypes[2] + 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 ExampleCors.ProtoReflect.Descriptor instead. +func (*ExampleCors) Descriptor() ([]byte, []int) { + return file_helloworld_v1_helloworld_proto_rawDescGZIP(), []int{2} +} + +func (x *ExampleCors) GetCors() *config.CorsConfig { + if x != nil { + return x.Cors + } + return nil +} + var File_helloworld_v1_helloworld_proto protoreflect.FileDescriptor var file_helloworld_v1_helloworld_proto_rawDesc = []byte{ 0x0a, 0x1e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x76, 0x31, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0d, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x76, 0x31, 0x1a, - 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, - 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x25, 0x0a, - 0x0f, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, - 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x32, 0x8a, 0x01, 0x0a, 0x0e, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x53, 0x65, + 0x14, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6f, 0x72, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x25, 0x0a, 0x0f, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x2c, 0x0a, 0x10, 0x53, 0x61, + 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x38, 0x0a, 0x0b, 0x45, 0x78, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x43, 0x6f, 0x72, 0x73, 0x12, 0x29, 0x0a, 0x04, 0x63, 0x6f, 0x72, 0x73, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, + 0x31, 0x2e, 0x43, 0x6f, 0x72, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x04, 0x63, 0x6f, + 0x72, 0x73, 0x32, 0x8a, 0x01, 0x0a, 0x0e, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x78, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x1e, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, @@ -162,19 +213,22 @@ func file_helloworld_v1_helloworld_proto_rawDescGZIP() []byte { return file_helloworld_v1_helloworld_proto_rawDescData } -var file_helloworld_v1_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_helloworld_v1_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_helloworld_v1_helloworld_proto_goTypes = []any{ - (*SayHelloRequest)(nil), // 0: helloworld.v1.SayHelloRequest - (*SayHelloResponse)(nil), // 1: helloworld.v1.SayHelloResponse + (*SayHelloRequest)(nil), // 0: helloworld.v1.SayHelloRequest + (*SayHelloResponse)(nil), // 1: helloworld.v1.SayHelloResponse + (*ExampleCors)(nil), // 2: helloworld.v1.ExampleCors + (*config.CorsConfig)(nil), // 3: config.v1.CorsConfig } var file_helloworld_v1_helloworld_proto_depIdxs = []int32{ - 0, // 0: helloworld.v1.GreeterService.SayHello:input_type -> helloworld.v1.SayHelloRequest - 1, // 1: helloworld.v1.GreeterService.SayHello:output_type -> helloworld.v1.SayHelloResponse - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 3, // 0: helloworld.v1.ExampleCors.cors:type_name -> config.v1.CorsConfig + 0, // 1: helloworld.v1.GreeterService.SayHello:input_type -> helloworld.v1.SayHelloRequest + 1, // 2: helloworld.v1.GreeterService.SayHello:output_type -> helloworld.v1.SayHelloResponse + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name } func init() { file_helloworld_v1_helloworld_proto_init() } @@ -188,7 +242,7 @@ func file_helloworld_v1_helloworld_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_helloworld_v1_helloworld_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 3, NumExtensions: 0, NumServices: 1, }, diff --git a/examples/services/helloworld/v1/helloworld.pb.validate.go b/examples/services/helloworld/v1/helloworld.pb.validate.go index 6b52a49..95c94c6 100644 --- a/examples/services/helloworld/v1/helloworld.pb.validate.go +++ b/examples/services/helloworld/v1/helloworld.pb.validate.go @@ -238,3 +238,131 @@ var _ interface { Cause() error ErrorName() string } = SayHelloResponseValidationError{} + +// Validate checks the field values on ExampleCors 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 *ExampleCors) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ExampleCors 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 ExampleCorsMultiError, or +// nil if none found. +func (m *ExampleCors) ValidateAll() error { + return m.validate(true) +} + +func (m *ExampleCors) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetCors()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, ExampleCorsValidationError{ + field: "Cors", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, ExampleCorsValidationError{ + field: "Cors", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetCors()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return ExampleCorsValidationError{ + field: "Cors", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return ExampleCorsMultiError(errors) + } + + return nil +} + +// ExampleCorsMultiError is an error wrapping multiple validation errors +// returned by ExampleCors.ValidateAll() if the designated constraints aren't met. +type ExampleCorsMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ExampleCorsMultiError) 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 ExampleCorsMultiError) AllErrors() []error { return m } + +// ExampleCorsValidationError is the validation error returned by +// ExampleCors.Validate if the designated constraints aren't met. +type ExampleCorsValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ExampleCorsValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ExampleCorsValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ExampleCorsValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ExampleCorsValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ExampleCorsValidationError) ErrorName() string { return "ExampleCorsValidationError" } + +// Error satisfies the builtin error interface +func (e ExampleCorsValidationError) 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 %sExampleCors.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ExampleCorsValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ExampleCorsValidationError{} diff --git a/examples/services/helloworld/v1/helloworld_gins.pb.go b/examples/services/helloworld/v1/helloworld_gins.pb.go index 6c80603..afa7e12 100644 --- a/examples/services/helloworld/v1/helloworld_gins.pb.go +++ b/examples/services/helloworld/v1/helloworld_gins.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-gins. DO NOT EDIT. // versions: -// - protoc-gen-go-gins v1.0.0 +// - protoc-gen-go-gins 0.0.84 // - protoc (unknown) // source: helloworld/v1/helloworld.proto @@ -10,7 +10,7 @@ import ( context "context" gin "github.com/gin-gonic/gin" binding "github.com/go-kratos/kratos/v2/transport/http/binding" - gins "github.com/origadmin/toolkits/runtime/kratos/transport/gins" + gins "github.com/origadmin/toolkits/runtime/transport/gins" ) // This is a compile-time assertion to ensure that this generated file @@ -23,17 +23,17 @@ const _ = gins.SupportPackageIsVersion1 const GreeterService_SayHello_OperationName = "/helloworld.v1.GreeterService/SayHello" -type GreeterServiceGINServer interface { +type GreeterServiceGINSServer interface { // SayHello Sends a greeting SayHello(context.Context, *SayHelloRequest) (*SayHelloResponse, error) } -func RegisterGreeterServiceGINServer(router gin.IRouter, srv GreeterServiceGINServer) { +func RegisterGreeterServiceGINSServer(router gin.IRouter, srv GreeterServiceGINSServer) { router.POST("/say_hello", _GreeterService_SayHello0_GIN_Handler(srv)) router.GET("/helloworld/:name", _GreeterService_SayHello1_GIN_Handler(srv)) } -func _GreeterService_SayHello0_GIN_Handler(srv GreeterServiceGINServer) func(ctx *gin.Context) { +func _GreeterService_SayHello0_GIN_Handler(srv GreeterServiceGINSServer) func(ctx *gin.Context) { return func(ctx *gin.Context) { var in SayHelloRequest if err := gins.BindBody(ctx, &in); err != nil { @@ -56,7 +56,7 @@ func _GreeterService_SayHello0_GIN_Handler(srv GreeterServiceGINServer) func(ctx } } -func _GreeterService_SayHello1_GIN_Handler(srv GreeterServiceGINServer) func(ctx *gin.Context) { +func _GreeterService_SayHello1_GIN_Handler(srv GreeterServiceGINSServer) func(ctx *gin.Context) { return func(ctx *gin.Context) { var in SayHelloRequest if err := gins.BindQuery(ctx, &in); err != nil { @@ -79,19 +79,19 @@ func _GreeterService_SayHello1_GIN_Handler(srv GreeterServiceGINServer) func(ctx } } -type GreeterServiceGINClient interface { +type GreeterServiceGINSClient interface { SayHello(ctx context.Context, req *SayHelloRequest, opts ...gins.CallOption) (rsp *SayHelloResponse, err error) } -type GreeterServiceGINClientImpl struct { +type GreeterServiceGINSClientImpl struct { cc *gins.Client } -func NewGreeterServiceGINClient(client *gins.Client) GreeterServiceGINClient { - return &GreeterServiceGINClientImpl{client} +func NewGreeterServiceGINSClient(client *gins.Client) GreeterServiceGINSClient { + return &GreeterServiceGINSClientImpl{client} } -func (c *GreeterServiceGINClientImpl) SayHello(ctx context.Context, in *SayHelloRequest, opts ...gins.CallOption) (*SayHelloResponse, error) { +func (c *GreeterServiceGINSClientImpl) SayHello(ctx context.Context, in *SayHelloRequest, opts ...gins.CallOption) (*SayHelloResponse, error) { var out SayHelloResponse pattern := "/helloworld/{name}" path := binding.EncodeURL(pattern, in, true) diff --git a/runtime/internal/example/example.pb.go b/runtime/internal/example/example.pb.go deleted file mode 100644 index 587f813..0000000 --- a/runtime/internal/example/example.pb.go +++ /dev/null @@ -1,158 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.35.1 -// protoc (unknown) -// source: example/example.proto - -package example - -import ( - config "github.com/origadmin/toolkits/runtime/config" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Example struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - Cors *config.CorsConfig `protobuf:"bytes,3,opt,name=cors,proto3" json:"cors,omitempty"` -} - -func (x *Example) Reset() { - *x = Example{} - mi := &file_example_example_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Example) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Example) ProtoMessage() {} - -func (x *Example) ProtoReflect() protoreflect.Message { - mi := &file_example_example_proto_msgTypes[0] - 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 Example.ProtoReflect.Descriptor instead. -func (*Example) Descriptor() ([]byte, []int) { - return file_example_example_proto_rawDescGZIP(), []int{0} -} - -func (x *Example) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Example) GetValue() string { - if x != nil { - return x.Value - } - return "" -} - -func (x *Example) GetCors() *config.CorsConfig { - if x != nil { - return x.Cors - } - return nil -} - -var File_example_example_proto protoreflect.FileDescriptor - -var file_example_example_proto_rawDesc = []byte{ - 0x0a, 0x15, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, - 0x1a, 0x14, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6f, 0x72, 0x73, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5e, 0x0a, 0x07, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, - 0x65, 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, 0x12, 0x29, 0x0a, 0x04, 0x63, - 0x6f, 0x72, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x63, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x72, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x52, 0x04, 0x63, 0x6f, 0x72, 0x73, 0x42, 0x8e, 0x01, 0x0a, 0x0b, 0x63, 0x6f, 0x6d, 0x2e, 0x65, - 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x42, 0x0c, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x50, - 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x35, 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, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x3b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0xa2, 0x02, 0x03, - 0x45, 0x58, 0x58, 0xaa, 0x02, 0x07, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0xca, 0x02, 0x07, - 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0xe2, 0x02, 0x13, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, - 0x65, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x07, - 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_example_example_proto_rawDescOnce sync.Once - file_example_example_proto_rawDescData = file_example_example_proto_rawDesc -) - -func file_example_example_proto_rawDescGZIP() []byte { - file_example_example_proto_rawDescOnce.Do(func() { - file_example_example_proto_rawDescData = protoimpl.X.CompressGZIP(file_example_example_proto_rawDescData) - }) - return file_example_example_proto_rawDescData -} - -var file_example_example_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_example_example_proto_goTypes = []any{ - (*Example)(nil), // 0: example.Example - (*config.CorsConfig)(nil), // 1: config.v1.CorsConfig -} -var file_example_example_proto_depIdxs = []int32{ - 1, // 0: example.Example.cors:type_name -> config.v1.CorsConfig - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_example_example_proto_init() } -func file_example_example_proto_init() { - if File_example_example_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_example_example_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_example_example_proto_goTypes, - DependencyIndexes: file_example_example_proto_depIdxs, - MessageInfos: file_example_example_proto_msgTypes, - }.Build() - File_example_example_proto = out.File - file_example_example_proto_rawDesc = nil - file_example_example_proto_goTypes = nil - file_example_example_proto_depIdxs = nil -} diff --git a/runtime/internal/example/example.pb.validate.go b/runtime/internal/example/example.pb.validate.go deleted file mode 100644 index 0f48473..0000000 --- a/runtime/internal/example/example.pb.validate.go +++ /dev/null @@ -1,167 +0,0 @@ -// Code generated by protoc-gen-validate. DO NOT EDIT. -// source: example/example.proto - -package example - -import ( - "bytes" - "errors" - "fmt" - "net" - "net/mail" - "net/url" - "regexp" - "sort" - "strings" - "time" - "unicode/utf8" - - "google.golang.org/protobuf/types/known/anypb" -) - -// ensure the imports are used -var ( - _ = bytes.MinRead - _ = errors.New("") - _ = fmt.Print - _ = utf8.UTFMax - _ = (*regexp.Regexp)(nil) - _ = (*strings.Reader)(nil) - _ = net.IPv4len - _ = time.Duration(0) - _ = (*url.URL)(nil) - _ = (*mail.Address)(nil) - _ = anypb.Any{} - _ = sort.Sort -) - -// Validate checks the field values on Example 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 *Example) Validate() error { - return m.validate(false) -} - -// ValidateAll checks the field values on Example 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 ExampleMultiError, or nil if none found. -func (m *Example) ValidateAll() error { - return m.validate(true) -} - -func (m *Example) validate(all bool) error { - if m == nil { - return nil - } - - var errors []error - - // no validation rules for Name - - // no validation rules for Value - - if all { - switch v := interface{}(m.GetCors()).(type) { - case interface{ ValidateAll() error }: - if err := v.ValidateAll(); err != nil { - errors = append(errors, ExampleValidationError{ - field: "Cors", - reason: "embedded message failed validation", - cause: err, - }) - } - case interface{ Validate() error }: - if err := v.Validate(); err != nil { - errors = append(errors, ExampleValidationError{ - field: "Cors", - reason: "embedded message failed validation", - cause: err, - }) - } - } - } else if v, ok := interface{}(m.GetCors()).(interface{ Validate() error }); ok { - if err := v.Validate(); err != nil { - return ExampleValidationError{ - field: "Cors", - reason: "embedded message failed validation", - cause: err, - } - } - } - - if len(errors) > 0 { - return ExampleMultiError(errors) - } - - return nil -} - -// ExampleMultiError is an error wrapping multiple validation errors returned -// by Example.ValidateAll() if the designated constraints aren't met. -type ExampleMultiError []error - -// Error returns a concatenation of all the error messages it wraps. -func (m ExampleMultiError) 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 ExampleMultiError) AllErrors() []error { return m } - -// ExampleValidationError is the validation error returned by Example.Validate -// if the designated constraints aren't met. -type ExampleValidationError struct { - field string - reason string - cause error - key bool -} - -// Field function returns field value. -func (e ExampleValidationError) Field() string { return e.field } - -// Reason function returns reason value. -func (e ExampleValidationError) Reason() string { return e.reason } - -// Cause function returns cause value. -func (e ExampleValidationError) Cause() error { return e.cause } - -// Key function returns key value. -func (e ExampleValidationError) Key() bool { return e.key } - -// ErrorName returns error name. -func (e ExampleValidationError) ErrorName() string { return "ExampleValidationError" } - -// Error satisfies the builtin error interface -func (e ExampleValidationError) 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 %sExample.%s: %s%s", - key, - e.field, - e.reason, - cause) -} - -var _ error = ExampleValidationError{} - -var _ interface { - Field() string - Reason() string - Key() bool - Cause() error - ErrorName() string -} = ExampleValidationError{} diff --git a/runtime/proto/example/example.proto b/runtime/proto/example/example.proto deleted file mode 100644 index 5311ce4..0000000 --- a/runtime/proto/example/example.proto +++ /dev/null @@ -1,13 +0,0 @@ -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