mirror of
https://github.com/purofle/remake_bot.git
synced 2025-06-17 23:03:30 +08:00
48 lines
841 B
Go
48 lines
841 B
Go
package bot
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type Country struct {
|
|
CountryName string `json:"country"`
|
|
Population int64 `json:"population"`
|
|
}
|
|
|
|
type RemakeData struct {
|
|
count int64
|
|
country string
|
|
gender string
|
|
}
|
|
|
|
type Remake struct {
|
|
CountryList []Country
|
|
TotalPopulation int64
|
|
RemakeCount map[int64]*RemakeData
|
|
}
|
|
|
|
func NewRemake() *Remake {
|
|
|
|
var remake Remake
|
|
|
|
rawJson, err := os.ReadFile("countries.json")
|
|
if err != nil {
|
|
log.Fatal("Error reading countries.json:", err)
|
|
}
|
|
|
|
if err = json.Unmarshal(rawJson, &remake.CountryList); err != nil {
|
|
log.Fatal("Error unmarshalling countries.json:", err)
|
|
}
|
|
|
|
remake.TotalPopulation = int64(0)
|
|
for _, country := range remake.CountryList {
|
|
remake.TotalPopulation += country.Population
|
|
}
|
|
|
|
remake.RemakeCount = make(map[int64]*RemakeData)
|
|
|
|
return &remake
|
|
}
|