feat:增加获取各个国家国旗方法
This commit is contained in:
26
country.go
26
country.go
@ -10,6 +10,7 @@ package consts
|
|||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Country struct {
|
type Country struct {
|
||||||
@ -55,6 +56,31 @@ func (country Country) GetLanguage() string {
|
|||||||
return country.Language
|
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
|
//go:embed country.json
|
||||||
var countryJSON []byte
|
var countryJSON []byte
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user