From 0d17ab798e54b92004c1b6bfda11feba68ab619d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 16 Dec 2025 11:18:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=90=84=E4=B8=AA=E5=9B=BD=E5=AE=B6=E5=9B=BD=E6=97=97=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- country.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/country.go b/country.go index 4973ff2..621af45 100644 --- a/country.go +++ b/country.go @@ -10,6 +10,7 @@ package consts import ( _ "embed" "encoding/json" + "fmt" ) type Country struct { @@ -55,6 +56,31 @@ func (country Country) GetLanguage() string { return country.Language } +// GetNationalFlag 获取国家国旗链接 +func (country Country) GetNationalFlag(width uint, height uint) string { + supportSizeList := []string{ + "16x12", "20x15", "24x18", "28x21", + "32x24", "36x27", "40x30", "48x36", + "56x42", "60x45", "64x48", "72x54", + "80x60", "84x63", "96x72", "108x81", + "112x84", "120x90", "128x96", "144x108", + "160x120", "192x144", "224x168", "256x192", + } + size := fmt.Sprintf("%vx%v", width, height) + isSupportSize := false + for _, itemSize := range supportSizeList { + if itemSize == size { + isSupportSize = true + break + } + } + if !isSupportSize { + // 不支持 + return "" + } + return fmt.Sprintf("https://flagcdn.com/%vx%v/%v.png", width, height, country.ShortLower) +} + //go:embed country.json var countryJSON []byte