fix: inject tag

This commit is contained in:
xuthus5 2023-06-25 23:02:26 +08:00
parent d9366d7755
commit 9c4404767e
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
5 changed files with 175 additions and 449 deletions

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.29.0
// protoc v4.22.2
// protoc-gen-go v1.26.0
// protoc v3.21.5
// source: example.proto
package gobuf
@ -63,7 +63,7 @@ type ListResp struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Items []*ListResp_Item `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` // 列表
Items []*ListResp_Item `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty" pson:"items" bson:"items"` // 列表
}
func (x *ListResp) Reset() {
@ -105,182 +105,19 @@ func (x *ListResp) GetItems() []*ListResp_Item {
return nil
}
type UploadReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *UploadReq) Reset() {
*x = UploadReq{}
if protoimpl.UnsafeEnabled {
mi := &file_example_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UploadReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UploadReq) ProtoMessage() {}
func (x *UploadReq) ProtoReflect() protoreflect.Message {
mi := &file_example_proto_msgTypes[2]
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 UploadReq.ProtoReflect.Descriptor instead.
func (*UploadReq) Descriptor() ([]byte, []int) {
return file_example_proto_rawDescGZIP(), []int{2}
}
type UploadResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *UploadResp) Reset() {
*x = UploadResp{}
if protoimpl.UnsafeEnabled {
mi := &file_example_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UploadResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UploadResp) ProtoMessage() {}
func (x *UploadResp) ProtoReflect() protoreflect.Message {
mi := &file_example_proto_msgTypes[3]
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 UploadResp.ProtoReflect.Descriptor instead.
func (*UploadResp) Descriptor() ([]byte, []int) {
return file_example_proto_rawDescGZIP(), []int{3}
}
type DeleteReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,omitempty"` // 文件名
}
func (x *DeleteReq) Reset() {
*x = DeleteReq{}
if protoimpl.UnsafeEnabled {
mi := &file_example_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeleteReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteReq) ProtoMessage() {}
func (x *DeleteReq) ProtoReflect() protoreflect.Message {
mi := &file_example_proto_msgTypes[4]
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 DeleteReq.ProtoReflect.Descriptor instead.
func (*DeleteReq) Descriptor() ([]byte, []int) {
return file_example_proto_rawDescGZIP(), []int{4}
}
func (x *DeleteReq) GetFilename() string {
if x != nil {
return x.Filename
}
return ""
}
type DeleteResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *DeleteResp) Reset() {
*x = DeleteResp{}
if protoimpl.UnsafeEnabled {
mi := &file_example_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeleteResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteResp) ProtoMessage() {}
func (x *DeleteResp) ProtoReflect() protoreflect.Message {
mi := &file_example_proto_msgTypes[5]
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 DeleteResp.ProtoReflect.Descriptor instead.
func (*DeleteResp) Descriptor() ([]byte, []int) {
return file_example_proto_rawDescGZIP(), []int{5}
}
type DownloadReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// @v: required
// @bson: "fffff"
// @json: "fffff"
F string `protobuf:"bytes,1,opt,name=f,proto3" json:"fffff" bson:"fffff"` // 文件地址
F string `protobuf:"bytes,1,opt,name=f,proto3" json:"f,omitempty" pson:"f" bson:"f"` // 文件地址
}
func (x *DownloadReq) Reset() {
*x = DownloadReq{}
if protoimpl.UnsafeEnabled {
mi := &file_example_proto_msgTypes[6]
mi := &file_example_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -293,7 +130,7 @@ func (x *DownloadReq) String() string {
func (*DownloadReq) ProtoMessage() {}
func (x *DownloadReq) ProtoReflect() protoreflect.Message {
mi := &file_example_proto_msgTypes[6]
mi := &file_example_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -306,7 +143,7 @@ func (x *DownloadReq) ProtoReflect() protoreflect.Message {
// Deprecated: Use DownloadReq.ProtoReflect.Descriptor instead.
func (*DownloadReq) Descriptor() ([]byte, []int) {
return file_example_proto_rawDescGZIP(), []int{6}
return file_example_proto_rawDescGZIP(), []int{2}
}
func (x *DownloadReq) GetF() string {
@ -325,7 +162,7 @@ type DownloadResp struct {
func (x *DownloadResp) Reset() {
*x = DownloadResp{}
if protoimpl.UnsafeEnabled {
mi := &file_example_proto_msgTypes[7]
mi := &file_example_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -338,7 +175,7 @@ func (x *DownloadResp) String() string {
func (*DownloadResp) ProtoMessage() {}
func (x *DownloadResp) ProtoReflect() protoreflect.Message {
mi := &file_example_proto_msgTypes[7]
mi := &file_example_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -351,83 +188,7 @@ func (x *DownloadResp) ProtoReflect() protoreflect.Message {
// Deprecated: Use DownloadResp.ProtoReflect.Descriptor instead.
func (*DownloadResp) Descriptor() ([]byte, []int) {
return file_example_proto_rawDescGZIP(), []int{7}
}
type UpdateUserInfoReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *UpdateUserInfoReq) Reset() {
*x = UpdateUserInfoReq{}
if protoimpl.UnsafeEnabled {
mi := &file_example_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UpdateUserInfoReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdateUserInfoReq) ProtoMessage() {}
func (x *UpdateUserInfoReq) ProtoReflect() protoreflect.Message {
mi := &file_example_proto_msgTypes[8]
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 UpdateUserInfoReq.ProtoReflect.Descriptor instead.
func (*UpdateUserInfoReq) Descriptor() ([]byte, []int) {
return file_example_proto_rawDescGZIP(), []int{8}
}
type UpdateUserInfoResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *UpdateUserInfoResp) Reset() {
*x = UpdateUserInfoResp{}
if protoimpl.UnsafeEnabled {
mi := &file_example_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UpdateUserInfoResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdateUserInfoResp) ProtoMessage() {}
func (x *UpdateUserInfoResp) ProtoReflect() protoreflect.Message {
mi := &file_example_proto_msgTypes[9]
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 UpdateUserInfoResp.ProtoReflect.Descriptor instead.
func (*UpdateUserInfoResp) Descriptor() ([]byte, []int) {
return file_example_proto_rawDescGZIP(), []int{9}
return file_example_proto_rawDescGZIP(), []int{3}
}
type ListResp_Item struct {
@ -435,15 +196,15 @@ type ListResp_Item struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,omitempty"` // 文件名
FileSize string `protobuf:"bytes,2,opt,name=file_size,json=fileSize,proto3" json:"file_size,omitempty"` // 文件大小
CreatedAt string `protobuf:"bytes,3,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` // 上传时间
Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,omitempty" pson:"filename" bson:"filename"` // 文件名
FileSize string `protobuf:"bytes,2,opt,name=file_size,json=fileSize,proto3" json:"file_size,omitempty" bson:"file_size" pson:"fileSize"` // 文件大小
CreatedAt string `protobuf:"bytes,3,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty" pson:"createdAt" bson:"created_at"` // 上传时间
}
func (x *ListResp_Item) Reset() {
*x = ListResp_Item{}
if protoimpl.UnsafeEnabled {
mi := &file_example_proto_msgTypes[10]
mi := &file_example_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -456,7 +217,7 @@ func (x *ListResp_Item) String() string {
func (*ListResp_Item) ProtoMessage() {}
func (x *ListResp_Item) ProtoReflect() protoreflect.Message {
mi := &file_example_proto_msgTypes[10]
mi := &file_example_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -508,39 +269,18 @@ var file_example_proto_rawDesc = []byte{
0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c,
0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64,
0x5f, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74,
0x65, 0x64, 0x41, 0x74, 0x22, 0x0b, 0x0a, 0x09, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65,
0x71, 0x22, 0x0c, 0x0a, 0x0a, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x22,
0x27, 0x0a, 0x09, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08,
0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x0c, 0x0a, 0x0a, 0x44, 0x65, 0x6c, 0x65,
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x1b, 0x0a, 0x0b, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f,
0x61, 0x64, 0x52, 0x65, 0x71, 0x12, 0x0c, 0x0a, 0x01, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x01, 0x66, 0x22, 0x0e, 0x0a, 0x0c, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x52,
0x65, 0x73, 0x70, 0x22, 0x13, 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65,
0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x22, 0x14, 0x0a, 0x12, 0x55, 0x70, 0x64, 0x61,
0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x32, 0xbb,
0x02, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12,
0x13, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x4c, 0x69, 0x73,
0x74, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65,
0x72, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x37, 0x0a, 0x06, 0x55, 0x70,
0x6c, 0x6f, 0x61, 0x64, 0x12, 0x15, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65,
0x72, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x63, 0x6f,
0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52,
0x65, 0x73, 0x70, 0x12, 0x37, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x15, 0x2e,
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74,
0x65, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65,
0x72, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x3d, 0x0a, 0x08,
0x65, 0x64, 0x41, 0x74, 0x22, 0x1b, 0x0a, 0x0b, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64,
0x52, 0x65, 0x71, 0x12, 0x0c, 0x0a, 0x01, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01,
0x66, 0x22, 0x0e, 0x0a, 0x0c, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73,
0x70, 0x32, 0x78, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x4c, 0x69, 0x73,
0x74, 0x12, 0x13, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x4c,
0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
0x6c, 0x65, 0x72, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x3d, 0x0a, 0x08,
0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x17, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72,
0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65,
0x71, 0x1a, 0x18, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x44,
0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x4f, 0x0a, 0x0e, 0x55,
0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x1d, 0x2e,
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74,
0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x1e, 0x2e, 0x63,
0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x32, 0x0a, 0x0a, 0x08,
0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x3b, 0x67,
0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x42, 0x0a, 0x5a, 0x08, 0x2e,
0x2f, 0x3b, 0x67, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -555,34 +295,22 @@ func file_example_proto_rawDescGZIP() []byte {
return file_example_proto_rawDescData
}
var file_example_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
var file_example_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_example_proto_goTypes = []interface{}{
(*ListReq)(nil), // 0: controller.ListReq
(*ListResp)(nil), // 1: controller.ListResp
(*UploadReq)(nil), // 2: controller.UploadReq
(*UploadResp)(nil), // 3: controller.UploadResp
(*DeleteReq)(nil), // 4: controller.DeleteReq
(*DeleteResp)(nil), // 5: controller.DeleteResp
(*DownloadReq)(nil), // 6: controller.DownloadReq
(*DownloadResp)(nil), // 7: controller.DownloadResp
(*UpdateUserInfoReq)(nil), // 8: controller.UpdateUserInfoReq
(*UpdateUserInfoResp)(nil), // 9: controller.UpdateUserInfoResp
(*ListResp_Item)(nil), // 10: controller.ListResp.Item
(*DownloadReq)(nil), // 2: controller.DownloadReq
(*DownloadResp)(nil), // 3: controller.DownloadResp
(*ListResp_Item)(nil), // 4: controller.ListResp.Item
}
var file_example_proto_depIdxs = []int32{
10, // 0: controller.ListResp.items:type_name -> controller.ListResp.Item
4, // 0: controller.ListResp.items:type_name -> controller.ListResp.Item
0, // 1: controller.File.List:input_type -> controller.ListReq
2, // 2: controller.File.Upload:input_type -> controller.UploadReq
4, // 3: controller.File.Delete:input_type -> controller.DeleteReq
6, // 4: controller.File.Download:input_type -> controller.DownloadReq
8, // 5: controller.File.UpdateUserInfo:input_type -> controller.UpdateUserInfoReq
1, // 6: controller.File.List:output_type -> controller.ListResp
3, // 7: controller.File.Upload:output_type -> controller.UploadResp
5, // 8: controller.File.Delete:output_type -> controller.DeleteResp
7, // 9: controller.File.Download:output_type -> controller.DownloadResp
9, // 10: controller.File.UpdateUserInfo:output_type -> controller.UpdateUserInfoResp
6, // [6:11] is the sub-list for method output_type
1, // [1:6] is the sub-list for method input_type
2, // 2: controller.File.Download:input_type -> controller.DownloadReq
1, // 3: controller.File.List:output_type -> controller.ListResp
3, // 4: controller.File.Download:output_type -> controller.DownloadResp
3, // [3:5] is the sub-list for method output_type
1, // [1:3] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
@ -619,54 +347,6 @@ func file_example_proto_init() {
}
}
file_example_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UploadReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_example_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UploadResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_example_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeleteReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_example_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeleteResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_example_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DownloadReq); i {
case 0:
return &v.state
@ -678,7 +358,7 @@ func file_example_proto_init() {
return nil
}
}
file_example_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
file_example_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DownloadResp); i {
case 0:
return &v.state
@ -690,31 +370,7 @@ func file_example_proto_init() {
return nil
}
}
file_example_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UpdateUserInfoReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_example_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UpdateUserInfoResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_example_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
file_example_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListResp_Item); i {
case 0:
return &v.state
@ -733,9 +389,9 @@ func file_example_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_example_proto_rawDesc,
NumEnums: 0,
NumMessages: 11,
NumMessages: 5,
NumExtensions: 0,
NumServices: 2,
NumServices: 1,
},
GoTypes: file_example_proto_goTypes,
DependencyIndexes: file_example_proto_depIdxs,

View File

@ -14,26 +14,11 @@ service File {
// @method: GET
// @api: /list
rpc List (ListReq) returns (ListResp);
// @desc:
// @author: Young Xu
// @method: POST
// @api: /upload
rpc Upload (UploadReq) returns (UploadResp);
// @desc:
// @author: Young Xu
// @method: POST
// @api: /delete
rpc Delete (DeleteReq) returns (DeleteResp);
// @desc:
// @author: Young Xu
// @method: GET
// @api: /download
rpc Download (DownloadReq) returns (DownloadResp);
// @desc:
// @author:
// @method:
// @api: /update_user_info
rpc UpdateUserInfo (UpdateUserInfoReq) returns (UpdateUserInfoResp);
}
@ -48,30 +33,9 @@ message ListResp {
repeated Item items = 1; //
}
message UploadReq {}
message UploadResp {}
message DeleteReq {
string filename = 1; //
}
message DeleteResp {}
message DownloadReq {
// @v: required
string f = 1; //
}
message DownloadResp {}
message UpdateUserInfoReq {}
message UpdateUserInfoResp {}
// @route_group: true
// @route_api: /
// @gen_to: ./
service UserInfo {}

View File

@ -11,6 +11,7 @@ import (
"path/filepath"
"regexp"
"strings"
"unicode"
)
var (
@ -30,8 +31,25 @@ type textArea struct {
CommentEnd int
}
type TagValueStyle int
const (
Underline TagValueStyle = iota
LowerCase
UpperCase
)
type InjectTagProps struct {
TagName string // tag name
Style TagValueStyle // tag value style, default underline
comment *ast.Comment
fieldName string
fieldValue string
}
type InjectTag struct {
inputFiles string
defaultTags map[string]TagValueStyle
}
func NewInjectTag(pbFiles string) *InjectTag {
@ -76,6 +94,16 @@ func (it *InjectTag) Inject() error {
return nil
}
func (it *InjectTag) WithTags(tags ...InjectTagProps) *InjectTag {
if len(it.defaultTags) == 0 {
it.defaultTags = make(map[string]TagValueStyle)
}
for _, tag := range tags {
it.defaultTags[tag.TagName] = tag.Style
}
return it
}
func (it *InjectTag) parserFile(inputPath string) (areas []textArea, err error) {
it.logf("parsing file %q for inject tag comments", inputPath)
fset := token.NewFileSet()
@ -111,6 +139,16 @@ func (it *InjectTag) parserFile(inputPath string) (areas []textArea, err error)
}
for _, field := range structDecl.Fields.List {
// skip if field name abnormal
if len(field.Names) != 1 {
continue
}
fieldName := field.Names[0].Name
if unicode.IsLower(rune(fieldName[0])) {
continue
}
// skip if field has no doc
var comments []*ast.Comment
@ -128,23 +166,26 @@ func (it *InjectTag) parserFile(inputPath string) (areas []textArea, err error)
comments = append(comments, field.Comment.List...)
}
for _, comment := range comments {
tag := it.tagFromComment(comment.Text)
if tag == "" {
tags := it.tagFromComment(field.Names[0].Name, comments)
if len(tags) == 0 {
continue
}
currentTag := field.Tag.Value
for _, tag := range tags {
area := textArea{
Start: int(field.Pos()),
End: int(field.End()),
CurrentTag: currentTag[1 : len(currentTag)-1],
InjectTag: tag,
CommentStart: int(comment.Pos()),
CommentEnd: int(comment.End()),
InjectTag: tag.fieldValue,
}
if tag.comment != nil {
area.CommentStart = int(tag.comment.Pos())
area.CommentEnd = int(tag.comment.End())
}
areas = append(areas, area)
}
}
}
//it.logf("parsed file %q, number of fields to inject custom tags: %d", inputPath, len(areas))
@ -186,18 +227,55 @@ func (it *InjectTag) logf(format string, v ...interface{}) {
log.Printf(format, v...)
}
func (it *InjectTag) tagFromComment(comment string) (tag string) {
bsonMatch := bsonComment.FindStringSubmatch(comment)
func (it *InjectTag) tagFromComment(fieldName string, comments []*ast.Comment) (tags []InjectTagProps) {
var commentInject = make(map[string]struct{})
for i := range comments {
bsonMatch := bsonComment.FindStringSubmatch(comments[i].Text)
if len(bsonMatch) == 2 {
return fmt.Sprintf(`bson:%v`, bsonMatch[1])
tags = append(tags, InjectTagProps{
TagName: "bson",
comment: comments[i],
fieldName: fieldName,
fieldValue: fmt.Sprintf(`bson:%v`, bsonMatch[1]),
})
commentInject["bson"] = struct{}{}
continue
}
jsonMatch := jsonComment.FindStringSubmatch(comment)
jsonMatch := jsonComment.FindStringSubmatch(comments[i].Text)
if len(jsonMatch) == 2 {
return fmt.Sprintf(`json:%v`, jsonMatch[1])
tags = append(tags, InjectTagProps{
TagName: "json",
comment: comments[i],
fieldName: fieldName,
fieldValue: fmt.Sprintf(`json:%v`, jsonMatch[1]),
})
commentInject["json"] = struct{}{}
continue
}
match := rComment.FindStringSubmatch(comment)
match := rComment.FindStringSubmatch(comments[i].Text)
if len(match) == 2 {
return match[1]
tagVal := match[1]
tagName := strings.Split(match[1], ":")[0]
tags = append(tags, InjectTagProps{
TagName: tagName,
comment: comments[i],
fieldName: fieldName,
fieldValue: tagVal,
})
commentInject[tagName] = struct{}{}
continue
}
}
for tag, style := range it.defaultTags {
_, exist := commentInject[tag]
if exist {
continue
}
tags = append(tags, InjectTagProps{
TagName: tag,
fieldName: fieldName,
fieldValue: fmt.Sprintf("%s:\"%s\"", tag, getFieldValue(fieldName, style)),
})
}
return
}
@ -239,6 +317,7 @@ func (ti *tagItems) override(nti tagItems) tagItems {
func (it *InjectTag) newTagItems(tag string) tagItems {
var items []tagItem
it.logf("new tag: %v\n", tag)
split := rTags.FindAllString(tag, -1)
for _, t := range split {
@ -254,9 +333,13 @@ func (it *InjectTag) newTagItems(tag string) tagItems {
func (it *InjectTag) injectTag(contents []byte, area textArea) (injected []byte) {
expr := make([]byte, area.End-area.Start)
copy(expr, contents[area.Start-1:area.End-1])
log.Println("expr: ", string(expr))
cti := it.newTagItems(area.CurrentTag)
log.Printf("cti: %v\n", cti)
iti := it.newTagItems(area.InjectTag)
log.Printf("iti: %v\n", iti)
ti := cti.override(iti)
log.Printf("ti: %v\n", ti)
expr = rInject.ReplaceAll(expr, []byte(fmt.Sprintf("`%s`", ti.format())))
injected = append(injected, contents[:area.Start-1]...)

View File

@ -7,6 +7,11 @@ import (
func TestInjectTag_Inject(t *testing.T) {
var parser = NewInjectTag("./example.pb.go")
err := parser.Inject()
err := parser.WithTags(InjectTagProps{
TagName: "bson",
}, InjectTagProps{
TagName: "pson",
Style: LowerCase,
}).Inject()
assert.Nil(t, err)
}

View File

@ -20,3 +20,21 @@ func calm2Case(src string) string {
}
return buffer.String()
}
func toLowerCamelCase(str string) string {
if len(str) != 0 {
return string(unicode.ToLower(rune(str[0]))) + str[1:]
}
return ""
}
func getFieldValue(fieldName string, cases TagValueStyle) string {
switch cases {
case Underline:
return calm2Case(fieldName)
case LowerCase:
return toLowerCamelCase(fieldName)
default:
return fieldName
}
}