2023-11-01 21:51:14 +00:00
|
|
|
package aid
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2023-11-05 01:58:00 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2023-11-01 21:51:14 +00:00
|
|
|
|
|
|
|
"gopkg.in/ini.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CS struct {
|
|
|
|
Database struct {
|
|
|
|
URI string
|
|
|
|
Type string
|
2023-11-02 17:50:52 +00:00
|
|
|
DropAllTables bool
|
2023-11-01 21:51:14 +00:00
|
|
|
}
|
|
|
|
Output struct {
|
|
|
|
Level string
|
|
|
|
}
|
2023-11-03 23:48:50 +00:00
|
|
|
API struct {
|
|
|
|
Host string
|
|
|
|
Port string
|
|
|
|
}
|
|
|
|
JWT struct {
|
|
|
|
Secret string
|
|
|
|
}
|
2023-11-05 01:58:00 +00:00
|
|
|
Fortnite struct {
|
|
|
|
Season int
|
|
|
|
Build float64
|
|
|
|
}
|
2023-11-01 21:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
Config *CS
|
|
|
|
)
|
|
|
|
|
|
|
|
func LoadConfig() {
|
|
|
|
Config = &CS{}
|
|
|
|
|
|
|
|
configPath := "config.ini"
|
|
|
|
if _, err := os.Stat(configPath); err != nil {
|
|
|
|
panic("config.ini not found! please rename default.config.ini to config.ini and complete")
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := ini.Load("config.ini")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-11-02 17:50:52 +00:00
|
|
|
Config.Database.DropAllTables = cfg.Section("database").Key("drop").MustBool(false)
|
2023-11-01 21:51:14 +00:00
|
|
|
Config.Database.URI = cfg.Section("database").Key("uri").String()
|
|
|
|
if Config.Database.URI == "" {
|
|
|
|
panic("Database URI is empty")
|
|
|
|
}
|
|
|
|
Config.Database.Type = cfg.Section("database").Key("type").String()
|
|
|
|
if Config.Database.Type == "" {
|
|
|
|
panic("Database Type is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Output.Level = cfg.Section("output").Key("level").String()
|
|
|
|
if Config.Output.Level == "" {
|
|
|
|
panic("Output Level is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if Config.Output.Level != "dev" && Config.Output.Level != "prod" && Config.Output.Level != "time" && Config.Output.Level != "info" {
|
|
|
|
panic("Output Level must be either dev or prod")
|
|
|
|
}
|
2023-11-03 23:48:50 +00:00
|
|
|
|
|
|
|
Config.API.Host = cfg.Section("api").Key("host").String()
|
|
|
|
if Config.API.Host == "" {
|
|
|
|
panic("API Host is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.API.Port = cfg.Section("api").Key("port").String()
|
|
|
|
if Config.API.Port == "" {
|
|
|
|
panic("API Port is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.JWT.Secret = cfg.Section("jwt").Key("secret").String()
|
|
|
|
if Config.JWT.Secret == "" {
|
|
|
|
panic("JWT Secret is empty")
|
|
|
|
}
|
2023-11-05 01:58:00 +00:00
|
|
|
|
|
|
|
build, err := cfg.Section("fortnite").Key("build").Float64()
|
|
|
|
if err != nil {
|
|
|
|
panic("Fortnite Build is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Fortnite.Build = build
|
|
|
|
|
|
|
|
buildStr := strconv.FormatFloat(build, 'f', -1, 64)
|
|
|
|
if buildStr == "" {
|
|
|
|
panic("Fortnite Build is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
buildInfo := strings.Split(buildStr, ".")
|
|
|
|
if len(buildInfo) < 2 {
|
|
|
|
panic("Fortnite Build is invalid")
|
|
|
|
}
|
|
|
|
|
|
|
|
parsedSeason, err := strconv.Atoi(buildInfo[0])
|
|
|
|
if err != nil {
|
|
|
|
panic("Fortnite Season is invalid")
|
|
|
|
}
|
|
|
|
|
|
|
|
Config.Fortnite.Season = parsedSeason
|
2023-11-01 21:51:14 +00:00
|
|
|
}
|