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转换错误")
+	}
 }