From 61c7feb8e9285d15301a2f9a24a93ab25866bfce Mon Sep 17 00:00:00 2001 From: yuanzhao <2206582181@qq.com> Date: Wed, 9 Aug 2023 21:14:32 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E4=BF=AE=E5=A4=8D=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=BA=A7=E5=88=AB=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/protoc.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/console/commands/protoc.go b/console/commands/protoc.go index 2a2c2fc..c455f79 100644 --- a/console/commands/protoc.go +++ b/console/commands/protoc.go @@ -188,6 +188,8 @@ func genProtoTag(out string) { if !packageStart { if bytes.Index(data, bytePackage) == 0 { packageStart = true + } else { + // 补充文件级别的 tag fileTags = append(fileTags, lineTags...) for s, t := range lineMapTags { fileMapTags[s] = t @@ -212,9 +214,9 @@ func genProtoTag(out string) { end = bytes.Index(data[start+begin:], []byte("`")) + start + begin } if len(tagValue) != 0 { - for s, t := range fileMapTags { - if _, ok := lineMapTags[s]; !ok { - lineMapTags[s] = t + for _, t := range fileTags { + if _, ok := lineMapTags[t.key]; !ok { + lineMapTags[t.key] = t lineTags = append(lineTags, t) } } @@ -224,7 +226,7 @@ func genProtoTag(out string) { switch lineTag.key { case "json": newStr = []byte(strings.ReplaceAll(string(newStr), "json:\""+string(tagValue)+",omitempty\"", "")) - newStr = append(newStr, []byte(lineTag.key+":\""+ + newStr = append(newStr, []byte(" "+lineTag.key+":\""+ strings.ReplaceAll(lineTag.val, "{name}", string(tagValue))+ "\"")...) default: