yjp 2 місяців тому
батько
коміт
0958bfc18c
3 змінених файлів з 31 додано та 1 видалено
  1. 1 1
      imgutils/imgutils.go
  2. 16 0
      strutils/strutils.go
  3. 14 0
      strutils/strutils_test.go

+ 1 - 1
imgutils/imgutils.go

@@ -278,7 +278,7 @@ func GetBase64FromUrl(url string) (string, error) {
 	return base64.StdEncoding.EncodeToString(data), nil
 }
 
-func ReplaceMiniQrLogo(qr image.Image, logo image.Image) ([]byte, error) {
+func ReplaceWechatMiniProgramQrLogo(qr image.Image, logo image.Image) ([]byte, error) {
 	logoSize := qr.Bounds().Dx() / 3
 	resizeLogo := resize.Resize(uint(logoSize), uint(logoSize), logo, resize.Bilinear)
 

+ 16 - 0
strutils/strutils.go

@@ -50,3 +50,19 @@ func GetUUID() string {
 func SimpleUUID() string {
 	return strings.ReplaceAll(GetUUID(), "-", "")
 }
+
+func GenerateUpperLetters(length int) []string {
+	var str []string
+	for i := 0; i < length; i++ {
+		str = append(str, string(rune('A'+i)))
+	}
+	return str
+}
+
+func GenerateLowerLetters(length int) []string {
+	var str []string
+	for i := 0; i < length; i++ {
+		str = append(str, string(rune('a'+i)))
+	}
+	return str
+}

+ 14 - 0
strutils/strutils_test.go

@@ -99,3 +99,17 @@ func TestUUID(t *testing.T) {
 		t.Fatal("生成uuid长度不为32")
 	}
 }
+
+func TestGenerateUpperLetters(t *testing.T) {
+	letters := GenerateUpperLetters(3)
+	if letters[0] != "A" || letters[1] != "B" || letters[2] != "C" {
+		t.Fatal("生成字母错误")
+	}
+}
+
+func TestGenerateLowerLetters(t *testing.T) {
+	letters := GenerateLowerLetters(3)
+	if letters[0] != "a" || letters[1] != "b" || letters[2] != "c" {
+		t.Fatal("生成字母错误")
+	}
+}