fix: inject tag
This commit is contained in:
parent
d9366d7755
commit
9c4404767e
432
example.pb.go
432
example.pb.go
@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.29.0
|
// protoc-gen-go v1.26.0
|
||||||
// protoc v4.22.2
|
// protoc v3.21.5
|
||||||
// source: example.proto
|
// source: example.proto
|
||||||
|
|
||||||
package gobuf
|
package gobuf
|
||||||
@ -63,7 +63,7 @@ type ListResp struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
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() {
|
func (x *ListResp) Reset() {
|
||||||
@ -105,182 +105,19 @@ func (x *ListResp) GetItems() []*ListResp_Item {
|
|||||||
return nil
|
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 {
|
type DownloadReq struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
// @v: required
|
// @v: required
|
||||||
// @bson: "fffff"
|
F string `protobuf:"bytes,1,opt,name=f,proto3" json:"f,omitempty" pson:"f" bson:"f"` // 文件地址
|
||||||
// @json: "fffff"
|
|
||||||
F string `protobuf:"bytes,1,opt,name=f,proto3" json:"fffff" bson:"fffff"` // 文件地址
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DownloadReq) Reset() {
|
func (x *DownloadReq) Reset() {
|
||||||
*x = DownloadReq{}
|
*x = DownloadReq{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_example_proto_msgTypes[6]
|
mi := &file_example_proto_msgTypes[2]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@ -293,7 +130,7 @@ func (x *DownloadReq) String() string {
|
|||||||
func (*DownloadReq) ProtoMessage() {}
|
func (*DownloadReq) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *DownloadReq) ProtoReflect() protoreflect.Message {
|
func (x *DownloadReq) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_example_proto_msgTypes[6]
|
mi := &file_example_proto_msgTypes[2]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@ -306,7 +143,7 @@ func (x *DownloadReq) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use DownloadReq.ProtoReflect.Descriptor instead.
|
// Deprecated: Use DownloadReq.ProtoReflect.Descriptor instead.
|
||||||
func (*DownloadReq) Descriptor() ([]byte, []int) {
|
func (*DownloadReq) Descriptor() ([]byte, []int) {
|
||||||
return file_example_proto_rawDescGZIP(), []int{6}
|
return file_example_proto_rawDescGZIP(), []int{2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DownloadReq) GetF() string {
|
func (x *DownloadReq) GetF() string {
|
||||||
@ -325,7 +162,7 @@ type DownloadResp struct {
|
|||||||
func (x *DownloadResp) Reset() {
|
func (x *DownloadResp) Reset() {
|
||||||
*x = DownloadResp{}
|
*x = DownloadResp{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_example_proto_msgTypes[7]
|
mi := &file_example_proto_msgTypes[3]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@ -338,7 +175,7 @@ func (x *DownloadResp) String() string {
|
|||||||
func (*DownloadResp) ProtoMessage() {}
|
func (*DownloadResp) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *DownloadResp) ProtoReflect() protoreflect.Message {
|
func (x *DownloadResp) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_example_proto_msgTypes[7]
|
mi := &file_example_proto_msgTypes[3]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@ -351,83 +188,7 @@ func (x *DownloadResp) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use DownloadResp.ProtoReflect.Descriptor instead.
|
// Deprecated: Use DownloadResp.ProtoReflect.Descriptor instead.
|
||||||
func (*DownloadResp) Descriptor() ([]byte, []int) {
|
func (*DownloadResp) Descriptor() ([]byte, []int) {
|
||||||
return file_example_proto_rawDescGZIP(), []int{7}
|
return file_example_proto_rawDescGZIP(), []int{3}
|
||||||
}
|
|
||||||
|
|
||||||
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}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListResp_Item struct {
|
type ListResp_Item struct {
|
||||||
@ -435,15 +196,15 @@ type ListResp_Item struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,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"` // 文件大小
|
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"` // 上传时间
|
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() {
|
func (x *ListResp_Item) Reset() {
|
||||||
*x = ListResp_Item{}
|
*x = ListResp_Item{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_example_proto_msgTypes[10]
|
mi := &file_example_proto_msgTypes[4]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@ -456,7 +217,7 @@ func (x *ListResp_Item) String() string {
|
|||||||
func (*ListResp_Item) ProtoMessage() {}
|
func (*ListResp_Item) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *ListResp_Item) ProtoReflect() protoreflect.Message {
|
func (x *ListResp_Item) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_example_proto_msgTypes[10]
|
mi := &file_example_proto_msgTypes[4]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
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,
|
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,
|
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,
|
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,
|
0x65, 0x64, 0x41, 0x74, 0x22, 0x1b, 0x0a, 0x0b, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64,
|
||||||
0x71, 0x22, 0x0c, 0x0a, 0x0a, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x22,
|
0x52, 0x65, 0x71, 0x12, 0x0c, 0x0a, 0x01, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01,
|
||||||
0x27, 0x0a, 0x09, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08,
|
0x66, 0x22, 0x0e, 0x0a, 0x0c, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73,
|
||||||
0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
|
0x70, 0x32, 0x78, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x4c, 0x69, 0x73,
|
||||||
0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x0c, 0x0a, 0x0a, 0x44, 0x65, 0x6c, 0x65,
|
0x74, 0x12, 0x13, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x4c,
|
||||||
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x1b, 0x0a, 0x0b, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f,
|
0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||||
0x61, 0x64, 0x52, 0x65, 0x71, 0x12, 0x0c, 0x0a, 0x01, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
0x6c, 0x65, 0x72, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x3d, 0x0a, 0x08,
|
||||||
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,
|
|
||||||
0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x17, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72,
|
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,
|
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,
|
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,
|
0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x42, 0x0a, 0x5a, 0x08, 0x2e,
|
||||||
0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x1d, 0x2e,
|
0x2f, 0x3b, 0x67, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -555,37 +295,25 @@ func file_example_proto_rawDescGZIP() []byte {
|
|||||||
return file_example_proto_rawDescData
|
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{}{
|
var file_example_proto_goTypes = []interface{}{
|
||||||
(*ListReq)(nil), // 0: controller.ListReq
|
(*ListReq)(nil), // 0: controller.ListReq
|
||||||
(*ListResp)(nil), // 1: controller.ListResp
|
(*ListResp)(nil), // 1: controller.ListResp
|
||||||
(*UploadReq)(nil), // 2: controller.UploadReq
|
(*DownloadReq)(nil), // 2: controller.DownloadReq
|
||||||
(*UploadResp)(nil), // 3: controller.UploadResp
|
(*DownloadResp)(nil), // 3: controller.DownloadResp
|
||||||
(*DeleteReq)(nil), // 4: controller.DeleteReq
|
(*ListResp_Item)(nil), // 4: controller.ListResp.Item
|
||||||
(*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
|
|
||||||
}
|
}
|
||||||
var file_example_proto_depIdxs = []int32{
|
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
|
0, // 1: controller.File.List:input_type -> controller.ListReq
|
||||||
2, // 2: controller.File.Upload:input_type -> controller.UploadReq
|
2, // 2: controller.File.Download:input_type -> controller.DownloadReq
|
||||||
4, // 3: controller.File.Delete:input_type -> controller.DeleteReq
|
1, // 3: controller.File.List:output_type -> controller.ListResp
|
||||||
6, // 4: controller.File.Download:input_type -> controller.DownloadReq
|
3, // 4: controller.File.Download:output_type -> controller.DownloadResp
|
||||||
8, // 5: controller.File.UpdateUserInfo:input_type -> controller.UpdateUserInfoReq
|
3, // [3:5] is the sub-list for method output_type
|
||||||
1, // 6: controller.File.List:output_type -> controller.ListResp
|
1, // [1:3] is the sub-list for method input_type
|
||||||
3, // 7: controller.File.Upload:output_type -> controller.UploadResp
|
1, // [1:1] is the sub-list for extension type_name
|
||||||
5, // 8: controller.File.Delete:output_type -> controller.DeleteResp
|
1, // [1:1] is the sub-list for extension extendee
|
||||||
7, // 9: controller.File.Download:output_type -> controller.DownloadResp
|
0, // [0:1] is the sub-list for field type_name
|
||||||
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
|
|
||||||
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_proto_init() }
|
func init() { file_example_proto_init() }
|
||||||
@ -619,54 +347,6 @@ func file_example_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_example_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
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 {
|
switch v := v.(*DownloadReq); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@ -678,7 +358,7 @@ func file_example_proto_init() {
|
|||||||
return nil
|
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 {
|
switch v := v.(*DownloadResp); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@ -690,31 +370,7 @@ func file_example_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_example_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
|
file_example_proto_msgTypes[4].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{} {
|
|
||||||
switch v := v.(*ListResp_Item); i {
|
switch v := v.(*ListResp_Item); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
@ -733,9 +389,9 @@ func file_example_proto_init() {
|
|||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: file_example_proto_rawDesc,
|
RawDescriptor: file_example_proto_rawDesc,
|
||||||
NumEnums: 0,
|
NumEnums: 0,
|
||||||
NumMessages: 11,
|
NumMessages: 5,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 2,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
GoTypes: file_example_proto_goTypes,
|
GoTypes: file_example_proto_goTypes,
|
||||||
DependencyIndexes: file_example_proto_depIdxs,
|
DependencyIndexes: file_example_proto_depIdxs,
|
||||||
|
@ -14,26 +14,11 @@ service File {
|
|||||||
// @method: GET
|
// @method: GET
|
||||||
// @api: /list
|
// @api: /list
|
||||||
rpc List (ListReq) returns (ListResp);
|
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: 下载
|
// @desc: 下载
|
||||||
// @author: Young Xu
|
// @author: Young Xu
|
||||||
// @method: GET
|
// @method: GET
|
||||||
// @api: /download
|
// @api: /download
|
||||||
rpc Download (DownloadReq) returns (DownloadResp);
|
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; // 列表
|
repeated Item items = 1; // 列表
|
||||||
}
|
}
|
||||||
|
|
||||||
message UploadReq {}
|
|
||||||
|
|
||||||
message UploadResp {}
|
|
||||||
|
|
||||||
message DeleteReq {
|
|
||||||
string filename = 1; // 文件名
|
|
||||||
}
|
|
||||||
|
|
||||||
message DeleteResp {}
|
|
||||||
|
|
||||||
message DownloadReq {
|
message DownloadReq {
|
||||||
// @v: required
|
// @v: required
|
||||||
string f = 1; // 文件地址
|
string f = 1; // 文件地址
|
||||||
}
|
}
|
||||||
|
|
||||||
message DownloadResp {}
|
message DownloadResp {}
|
||||||
|
|
||||||
message UpdateUserInfoReq {}
|
|
||||||
|
|
||||||
message UpdateUserInfoResp {}
|
|
||||||
|
|
||||||
|
|
||||||
// @route_group: true
|
|
||||||
// @route_api: /
|
|
||||||
// @gen_to: ./
|
|
||||||
service UserInfo {}
|
|
||||||
|
|
||||||
|
131
inject_tag.go
131
inject_tag.go
@ -11,6 +11,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -30,8 +31,25 @@ type textArea struct {
|
|||||||
CommentEnd int
|
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 {
|
type InjectTag struct {
|
||||||
inputFiles string
|
inputFiles string
|
||||||
|
defaultTags map[string]TagValueStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInjectTag(pbFiles string) *InjectTag {
|
func NewInjectTag(pbFiles string) *InjectTag {
|
||||||
@ -76,6 +94,16 @@ func (it *InjectTag) Inject() error {
|
|||||||
return nil
|
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) {
|
func (it *InjectTag) parserFile(inputPath string) (areas []textArea, err error) {
|
||||||
it.logf("parsing file %q for inject tag comments", inputPath)
|
it.logf("parsing file %q for inject tag comments", inputPath)
|
||||||
fset := token.NewFileSet()
|
fset := token.NewFileSet()
|
||||||
@ -111,6 +139,16 @@ func (it *InjectTag) parserFile(inputPath string) (areas []textArea, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, field := range structDecl.Fields.List {
|
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
|
// skip if field has no doc
|
||||||
var comments []*ast.Comment
|
var comments []*ast.Comment
|
||||||
|
|
||||||
@ -128,23 +166,26 @@ func (it *InjectTag) parserFile(inputPath string) (areas []textArea, err error)
|
|||||||
comments = append(comments, field.Comment.List...)
|
comments = append(comments, field.Comment.List...)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, comment := range comments {
|
tags := it.tagFromComment(field.Names[0].Name, comments)
|
||||||
tag := it.tagFromComment(comment.Text)
|
if len(tags) == 0 {
|
||||||
if tag == "" {
|
continue
|
||||||
continue
|
}
|
||||||
}
|
|
||||||
|
|
||||||
currentTag := field.Tag.Value
|
currentTag := field.Tag.Value
|
||||||
|
for _, tag := range tags {
|
||||||
area := textArea{
|
area := textArea{
|
||||||
Start: int(field.Pos()),
|
Start: int(field.Pos()),
|
||||||
End: int(field.End()),
|
End: int(field.End()),
|
||||||
CurrentTag: currentTag[1 : len(currentTag)-1],
|
CurrentTag: currentTag[1 : len(currentTag)-1],
|
||||||
InjectTag: tag,
|
InjectTag: tag.fieldValue,
|
||||||
CommentStart: int(comment.Pos()),
|
}
|
||||||
CommentEnd: int(comment.End()),
|
if tag.comment != nil {
|
||||||
|
area.CommentStart = int(tag.comment.Pos())
|
||||||
|
area.CommentEnd = int(tag.comment.End())
|
||||||
}
|
}
|
||||||
areas = append(areas, area)
|
areas = append(areas, area)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//it.logf("parsed file %q, number of fields to inject custom tags: %d", inputPath, len(areas))
|
//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...)
|
log.Printf(format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *InjectTag) tagFromComment(comment string) (tag string) {
|
func (it *InjectTag) tagFromComment(fieldName string, comments []*ast.Comment) (tags []InjectTagProps) {
|
||||||
bsonMatch := bsonComment.FindStringSubmatch(comment)
|
var commentInject = make(map[string]struct{})
|
||||||
if len(bsonMatch) == 2 {
|
for i := range comments {
|
||||||
return fmt.Sprintf(`bson:%v`, bsonMatch[1])
|
bsonMatch := bsonComment.FindStringSubmatch(comments[i].Text)
|
||||||
|
if len(bsonMatch) == 2 {
|
||||||
|
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(comments[i].Text)
|
||||||
|
if len(jsonMatch) == 2 {
|
||||||
|
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(comments[i].Text)
|
||||||
|
if len(match) == 2 {
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
jsonMatch := jsonComment.FindStringSubmatch(comment)
|
for tag, style := range it.defaultTags {
|
||||||
if len(jsonMatch) == 2 {
|
_, exist := commentInject[tag]
|
||||||
return fmt.Sprintf(`json:%v`, jsonMatch[1])
|
if exist {
|
||||||
}
|
continue
|
||||||
match := rComment.FindStringSubmatch(comment)
|
}
|
||||||
if len(match) == 2 {
|
tags = append(tags, InjectTagProps{
|
||||||
return match[1]
|
TagName: tag,
|
||||||
|
fieldName: fieldName,
|
||||||
|
fieldValue: fmt.Sprintf("%s:\"%s\"", tag, getFieldValue(fieldName, style)),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -239,6 +317,7 @@ func (ti *tagItems) override(nti tagItems) tagItems {
|
|||||||
|
|
||||||
func (it *InjectTag) newTagItems(tag string) tagItems {
|
func (it *InjectTag) newTagItems(tag string) tagItems {
|
||||||
var items []tagItem
|
var items []tagItem
|
||||||
|
it.logf("new tag: %v\n", tag)
|
||||||
split := rTags.FindAllString(tag, -1)
|
split := rTags.FindAllString(tag, -1)
|
||||||
|
|
||||||
for _, t := range split {
|
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) {
|
func (it *InjectTag) injectTag(contents []byte, area textArea) (injected []byte) {
|
||||||
expr := make([]byte, area.End-area.Start)
|
expr := make([]byte, area.End-area.Start)
|
||||||
copy(expr, contents[area.Start-1:area.End-1])
|
copy(expr, contents[area.Start-1:area.End-1])
|
||||||
|
log.Println("expr: ", string(expr))
|
||||||
cti := it.newTagItems(area.CurrentTag)
|
cti := it.newTagItems(area.CurrentTag)
|
||||||
|
log.Printf("cti: %v\n", cti)
|
||||||
iti := it.newTagItems(area.InjectTag)
|
iti := it.newTagItems(area.InjectTag)
|
||||||
|
log.Printf("iti: %v\n", iti)
|
||||||
ti := cti.override(iti)
|
ti := cti.override(iti)
|
||||||
|
log.Printf("ti: %v\n", ti)
|
||||||
expr = rInject.ReplaceAll(expr, []byte(fmt.Sprintf("`%s`", ti.format())))
|
expr = rInject.ReplaceAll(expr, []byte(fmt.Sprintf("`%s`", ti.format())))
|
||||||
|
|
||||||
injected = append(injected, contents[:area.Start-1]...)
|
injected = append(injected, contents[:area.Start-1]...)
|
||||||
|
@ -7,6 +7,11 @@ import (
|
|||||||
|
|
||||||
func TestInjectTag_Inject(t *testing.T) {
|
func TestInjectTag_Inject(t *testing.T) {
|
||||||
var parser = NewInjectTag("./example.pb.go")
|
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)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
18
utils.go
18
utils.go
@ -20,3 +20,21 @@ func calm2Case(src string) string {
|
|||||||
}
|
}
|
||||||
return buffer.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user