浏览代码

修改模板ids

yjp 3 月之前
父节点
当前提交
48fcbe09fb
共有 2 个文件被更改,包括 57 次插入0 次删除
  1. 45 0
      template/template_func.go
  2. 12 0
      template/template_test.go

+ 45 - 0
template/template_func.go

@@ -78,6 +78,21 @@ func Id(s string) string {
 		return s[0:index] + "Id"
 	}
 
+	if strings.HasSuffix(s, "IDs") {
+		index := strings.LastIndex(s, "IDs")
+		return s[0:index] + "Ids"
+	}
+
+	if strings.HasSuffix(s, "ids") {
+		index := strings.LastIndex(s, "ids")
+		return s[0:index] + "Ids"
+	}
+
+	if strings.HasSuffix(s, "iDs") {
+		index := strings.LastIndex(s, "iDs")
+		return s[0:index] + "Ids"
+	}
+
 	return s
 }
 
@@ -97,6 +112,21 @@ func ID(s string) string {
 		return s[0:index] + "ID"
 	}
 
+	if strings.HasSuffix(s, "Ids") {
+		index := strings.LastIndex(s, "Ids")
+		return s[0:index] + "IDs"
+	}
+
+	if strings.HasSuffix(s, "ids") {
+		index := strings.LastIndex(s, "ids")
+		return s[0:index] + "IDs"
+	}
+
+	if strings.HasSuffix(s, "iDs") {
+		index := strings.LastIndex(s, "iDs")
+		return s[0:index] + "IDs"
+	}
+
 	return s
 }
 
@@ -116,6 +146,21 @@ func id(s string) string {
 		return s[0:index] + "id"
 	}
 
+	if strings.HasSuffix(s, "Ids") {
+		index := strings.LastIndex(s, "Ids")
+		return s[0:index] + "ids"
+	}
+
+	if strings.HasSuffix(s, "IDs") {
+		index := strings.LastIndex(s, "IDs")
+		return s[0:index] + "ids"
+	}
+
+	if strings.HasSuffix(s, "iDs") {
+		index := strings.LastIndex(s, "iDs")
+		return s[0:index] + "ids"
+	}
+
 	return s
 }
 

+ 12 - 0
template/template_test.go

@@ -137,4 +137,16 @@ func TestIDTemplateFunc(t *testing.T) {
 	if ID("Middleid") != "MiddleID" {
 		t.Fatal("Id转换错误")
 	}
+
+	if Id("MiddleIDs") != "MiddleIds" {
+		t.Fatal("Id转换错误")
+	}
+
+	if id("MiddleIDs") != "Middleids" {
+		t.Fatal("Id转换错误")
+	}
+
+	if ID("Middleids") != "MiddleIDs" {
+		t.Fatal("Id转换错误")
+	}
 }