Browse Source

修改模板ids

yjp 3 months ago
parent
commit
48fcbe09fb
2 changed files with 57 additions and 0 deletions
  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转换错误")
+	}
 }