feat:增加获取各个国家国旗方法

This commit is contained in:
2025-12-16 11:18:25 +08:00
parent 78b15cc79a
commit 0d17ab798e

View File

@ -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