diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod index c654dde..5c57326 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/google/uuid v1.6.0 github.com/infraboard/mcube/v2 v2.0.44 github.com/rs/zerolog v1.32.0 - golang.org/x/crypto v0.23.0 + golang.org/x/crypto v0.31.0 google.golang.org/protobuf v1.34.1 gopkg.in/natefinch/lumberjack.v2 v2.2.1 gopkg.in/yaml.v3 v3.0.1 @@ -76,9 +76,9 @@ require ( go.opentelemetry.io/proto/otlp v1.1.0 // indirect golang.org/x/arch v0.8.0 // indirect golang.org/x/net v0.25.0 // indirect - golang.org/x/sync v0.6.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect + golang.org/x/sync v0.10.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/grpc v1.63.2 // indirect diff --git a/go.sum b/go.sum index bf60ce0..1cf13f7 100644 --- a/go.sum +++ b/go.sum @@ -169,20 +169,20 @@ go.opentelemetry.io/proto/otlp v1.1.0/go.mod h1:GpBHCBWiqvVLDqmHZsoMM3C5ySeKTC7e golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:jFNzHPIeuzhdRwVhbZdiym9q0ory/xY3sA+v2wPg8I0= diff --git a/skills/protobuf/hello.pb.go b/skills/protobuf/hello.pb.go index dc7c9d8..b3bb62c 100644 --- a/skills/protobuf/hello.pb.go +++ b/skills/protobuf/hello.pb.go @@ -9,6 +9,7 @@ package protobuf import ( 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" unsafe "unsafe" @@ -21,9 +22,104 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type DESCRIBE_BY int32 + +const ( + DESCRIBE_BY_ID DESCRIBE_BY = 0 + DESCRIBE_BY_NAME DESCRIBE_BY = 1 +) + +// Enum value maps for DESCRIBE_BY. +var ( + DESCRIBE_BY_name = map[int32]string{ + 0: "ID", + 1: "NAME", + } + DESCRIBE_BY_value = map[string]int32{ + "ID": 0, + "NAME": 1, + } +) + +func (x DESCRIBE_BY) Enum() *DESCRIBE_BY { + p := new(DESCRIBE_BY) + *p = x + return p +} + +func (x DESCRIBE_BY) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (DESCRIBE_BY) Descriptor() protoreflect.EnumDescriptor { + return file_skills_protobuf_hello_proto_enumTypes[0].Descriptor() +} + +func (DESCRIBE_BY) Type() protoreflect.EnumType { + return &file_skills_protobuf_hello_proto_enumTypes[0] +} + +func (x DESCRIBE_BY) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use DESCRIBE_BY.Descriptor instead. +func (DESCRIBE_BY) EnumDescriptor() ([]byte, []int) { + return file_skills_protobuf_hello_proto_rawDescGZIP(), []int{0} +} + +type EVENT_TYPE int32 + +const ( + EVENT_TYPE_ECS EVENT_TYPE = 0 + EVENT_TYPE_RDS EVENT_TYPE = 1 +) + +// Enum value maps for EVENT_TYPE. +var ( + EVENT_TYPE_name = map[int32]string{ + 0: "ECS", + 1: "RDS", + } + EVENT_TYPE_value = map[string]int32{ + "ECS": 0, + "RDS": 1, + } +) + +func (x EVENT_TYPE) Enum() *EVENT_TYPE { + p := new(EVENT_TYPE) + *p = x + return p +} + +func (x EVENT_TYPE) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (EVENT_TYPE) Descriptor() protoreflect.EnumDescriptor { + return file_skills_protobuf_hello_proto_enumTypes[1].Descriptor() +} + +func (EVENT_TYPE) Type() protoreflect.EnumType { + return &file_skills_protobuf_hello_proto_enumTypes[1] +} + +func (x EVENT_TYPE) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use EVENT_TYPE.Descriptor instead. +func (EVENT_TYPE) EnumDescriptor() ([]byte, []int) { + return file_skills_protobuf_hello_proto_rawDescGZIP(), []int{1} +} + type HelloRequest struct { state protoimpl.MessageState `protogen:"open.v1"` MyName string `protobuf:"bytes,1,opt,name=my_name,json=myName,proto3" json:"my_name,omitempty"` + Age int64 `protobuf:"varint,2,opt,name=age,proto3" json:"age,omitempty"` + MagicNumber []int64 `protobuf:"varint,3,rep,packed,name=magic_number,json=magicNumber,proto3" json:"magic_number,omitempty"` + Extras map[string]string `protobuf:"bytes,4,rep,name=extras,proto3" json:"extras,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -65,6 +161,27 @@ func (x *HelloRequest) GetMyName() string { return "" } +func (x *HelloRequest) GetAge() int64 { + if x != nil { + return x.Age + } + return 0 +} + +func (x *HelloRequest) GetMagicNumber() []int64 { + if x != nil { + return x.MagicNumber + } + return nil +} + +func (x *HelloRequest) GetExtras() map[string]string { + if x != nil { + return x.Extras + } + return nil +} + type HelloResponse struct { state protoimpl.MessageState `protogen:"open.v1"` Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` @@ -109,21 +226,200 @@ func (x *HelloResponse) GetMessage() string { return "" } +type EVENT_ECS struct { + state protoimpl.MessageState `protogen:"open.v1"` + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EVENT_ECS) Reset() { + *x = EVENT_ECS{} + mi := &file_skills_protobuf_hello_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EVENT_ECS) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EVENT_ECS) ProtoMessage() {} + +func (x *EVENT_ECS) ProtoReflect() protoreflect.Message { + mi := &file_skills_protobuf_hello_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 EVENT_ECS.ProtoReflect.Descriptor instead. +func (*EVENT_ECS) Descriptor() ([]byte, []int) { + return file_skills_protobuf_hello_proto_rawDescGZIP(), []int{2} +} + +func (x *EVENT_ECS) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type EVENT_RDS struct { + state protoimpl.MessageState `protogen:"open.v1"` + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EVENT_RDS) Reset() { + *x = EVENT_RDS{} + mi := &file_skills_protobuf_hello_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EVENT_RDS) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EVENT_RDS) ProtoMessage() {} + +func (x *EVENT_RDS) ProtoReflect() protoreflect.Message { + mi := &file_skills_protobuf_hello_proto_msgTypes[3] + 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 EVENT_RDS.ProtoReflect.Descriptor instead. +func (*EVENT_RDS) Descriptor() ([]byte, []int) { + return file_skills_protobuf_hello_proto_rawDescGZIP(), []int{3} +} + +func (x *EVENT_RDS) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type Event struct { + state protoimpl.MessageState `protogen:"open.v1"` + // 事件类型(ECS/RDS/...) + // ECS + Type EVENT_TYPE `protobuf:"varint,1,opt,name=type,proto3,enum=hello.EVENT_TYPE" json:"type,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Detail []*anypb.Any `protobuf:"bytes,3,rep,name=detail,proto3" json:"detail,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Event) Reset() { + *x = Event{} + mi := &file_skills_protobuf_hello_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Event) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Event) ProtoMessage() {} + +func (x *Event) ProtoReflect() protoreflect.Message { + mi := &file_skills_protobuf_hello_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 Event.ProtoReflect.Descriptor instead. +func (*Event) Descriptor() ([]byte, []int) { + return file_skills_protobuf_hello_proto_rawDescGZIP(), []int{4} +} + +func (x *Event) GetType() EVENT_TYPE { + if x != nil { + return x.Type + } + return EVENT_TYPE_ECS +} + +func (x *Event) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *Event) GetDetail() []*anypb.Any { + if x != nil { + return x.Detail + } + return nil +} + var File_skills_protobuf_hello_proto protoreflect.FileDescriptor var file_skills_protobuf_hello_proto_rawDesc = string([]byte{ 0x0a, 0x1b, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x68, - 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x27, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x6d, 0x79, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x29, 0x0a, - 0x0d, 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, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x6c, - 0x61, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x63, 0x6f, 0x75, 0x72, 0x73, 0x65, - 0x2d, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x67, 0x6f, 0x31, 0x37, 0x2f, 0x73, 0x6b, - 0x69, 0x6c, 0x6c, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x6c, 0x6c, 0x6f, 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, + 0xd0, 0x01, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x17, 0x0a, 0x07, 0x6d, 0x79, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x6d, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x67, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x61, 0x67, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x6d, + 0x61, 0x67, 0x69, 0x63, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x03, 0x20, 0x03, 0x28, + 0x03, 0x52, 0x0b, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x37, + 0x0a, 0x06, 0x65, 0x78, 0x74, 0x72, 0x61, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, + 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x72, 0x61, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, + 0x06, 0x65, 0x78, 0x74, 0x72, 0x61, 0x73, 0x1a, 0x39, 0x0a, 0x0b, 0x45, 0x78, 0x74, 0x72, 0x61, + 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, 0x22, 0x29, 0x0a, 0x0d, 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, 0x25, 0x0a, + 0x09, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f, 0x45, 0x43, 0x53, 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, 0x25, 0x0a, 0x09, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f, 0x52, 0x44, + 0x53, 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, 0x76, 0x0a, 0x05, 0x45, + 0x76, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0e, 0x32, 0x11, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x45, 0x56, 0x45, 0x4e, 0x54, + 0x5f, 0x54, 0x59, 0x50, 0x45, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x2c, 0x0a, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x18, + 0x03, 0x20, 0x03, 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, 0x64, 0x65, 0x74, + 0x61, 0x69, 0x6c, 0x2a, 0x1f, 0x0a, 0x0b, 0x44, 0x45, 0x53, 0x43, 0x52, 0x49, 0x42, 0x45, 0x5f, + 0x42, 0x59, 0x12, 0x06, 0x0a, 0x02, 0x49, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x41, + 0x4d, 0x45, 0x10, 0x01, 0x2a, 0x1e, 0x0a, 0x0a, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f, 0x54, 0x59, + 0x50, 0x45, 0x12, 0x07, 0x0a, 0x03, 0x45, 0x43, 0x53, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x52, + 0x44, 0x53, 0x10, 0x01, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x6c, 0x61, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x63, 0x6f, 0x75, 0x72, 0x73, 0x65, 0x2d, 0x70, 0x72, 0x6f, + 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x67, 0x6f, 0x31, 0x37, 0x2f, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x73, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, }) var ( @@ -138,17 +434,28 @@ func file_skills_protobuf_hello_proto_rawDescGZIP() []byte { return file_skills_protobuf_hello_proto_rawDescData } -var file_skills_protobuf_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_skills_protobuf_hello_proto_enumTypes = make([]protoimpl.EnumInfo, 2) +var file_skills_protobuf_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_skills_protobuf_hello_proto_goTypes = []any{ - (*HelloRequest)(nil), // 0: hello.HelloRequest - (*HelloResponse)(nil), // 1: hello.HelloResponse + (DESCRIBE_BY)(0), // 0: hello.DESCRIBE_BY + (EVENT_TYPE)(0), // 1: hello.EVENT_TYPE + (*HelloRequest)(nil), // 2: hello.HelloRequest + (*HelloResponse)(nil), // 3: hello.HelloResponse + (*EVENT_ECS)(nil), // 4: hello.EVENT_ECS + (*EVENT_RDS)(nil), // 5: hello.EVENT_RDS + (*Event)(nil), // 6: hello.Event + nil, // 7: hello.HelloRequest.ExtrasEntry + (*anypb.Any)(nil), // 8: google.protobuf.Any } var file_skills_protobuf_hello_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] 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 + 7, // 0: hello.HelloRequest.extras:type_name -> hello.HelloRequest.ExtrasEntry + 1, // 1: hello.Event.type:type_name -> hello.EVENT_TYPE + 8, // 2: hello.Event.detail:type_name -> google.protobuf.Any + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_skills_protobuf_hello_proto_init() } @@ -161,13 +468,14 @@ func file_skills_protobuf_hello_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_skills_protobuf_hello_proto_rawDesc), len(file_skills_protobuf_hello_proto_rawDesc)), - NumEnums: 0, - NumMessages: 2, + NumEnums: 2, + NumMessages: 6, NumExtensions: 0, NumServices: 0, }, GoTypes: file_skills_protobuf_hello_proto_goTypes, DependencyIndexes: file_skills_protobuf_hello_proto_depIdxs, + EnumInfos: file_skills_protobuf_hello_proto_enumTypes, MessageInfos: file_skills_protobuf_hello_proto_msgTypes, }.Build() File_skills_protobuf_hello_proto = out.File diff --git a/skills/protobuf/hello.pb_test.go b/skills/protobuf/hello.pb_test.go new file mode 100644 index 0000000..fb71d0e --- /dev/null +++ b/skills/protobuf/hello.pb_test.go @@ -0,0 +1,52 @@ +package protobuf_test + +import ( + "testing" + + "gitlab.com/go-course-project/go17/skills/protobuf" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" +) + +func TestHelloRequest(t *testing.T) { + req := &protobuf.HelloRequest{MyName: "bob", Age: 64} + data, err := proto.Marshal(req) + if err != nil { + t.Fatal(err) + } + t.Log(string(data)) + + req2 := &protobuf.HelloRequest{} + err = proto.Unmarshal(data, req2) + if err != nil { + t.Fatal(err) + } + t.Log(req2) + + t.Log(protobuf.DESCRIBE_BY_ID) +} + +func TestAny(t *testing.T) { + // 1. Pack + req := &protobuf.Event{ + Type: protobuf.EVENT_TYPE_ECS, + Message: "test for any", + Detail: []*anypb.Any{}, + } + + ecsAny, err := anypb.New(&protobuf.EVENT_ECS{Message: "1"}) + if err != nil { + t.Fatal(err) + } + req.Detail = append(req.Detail, ecsAny) + + t.Log(req) + + // 2. Unpack + t.Log(req.Detail[0]) + ecsEvent := &protobuf.EVENT_ECS{} + if err := req.Detail[0].UnmarshalTo(ecsEvent); err != nil { + t.Fatal(err) + } + t.Log(ecsEvent) +} diff --git a/skills/protobuf/hello.proto b/skills/protobuf/hello.proto index 1792e61..1b0bc33 100644 --- a/skills/protobuf/hello.proto +++ b/skills/protobuf/hello.proto @@ -3,21 +3,46 @@ syntax = "proto3"; package hello; option go_package="gitlab.com/go-course-project/go17/skills/protobuf"; -// type HelloRequest struct { -// MyName string `json:"my_name"` -// } - -// type HelloResponse struct { -// Message string `json:"message"` -// } +import "google/protobuf/any.proto"; message HelloRequest { string my_name = 1; + int64 age = 2; + repeated int64 magic_number = 3; + map extras = 4; } message HelloResponse { string message = 1; } +enum DESCRIBE_BY { + ID = 0; + NAME = 1; +} + +enum EVENT_TYPE { + ECS = 0; + RDS = 1; +} + +message EVENT_ECS { + string message = 1; +} + +message EVENT_RDS { + string message = 1; +} + +message Event { + // 事件类型(ECS/RDS/...) + // ECS + EVENT_TYPE type = 1; + string message = 2; + repeated google.protobuf.Any detail = 3; +} + + +