Skip to content

Commit

Permalink
Configの取得方法を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
Shugo Kawamura committed Aug 4, 2023
1 parent 8a33c0f commit 8a49090
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 52 deletions.
2 changes: 1 addition & 1 deletion PATCHNOTE.MD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Patch Notes and ROADMAPS

ROADMAP OF get5-web-go (temporary,Roadmap and update details may heavily change)
- v0.1.0(ETA. Spring 2020)
- v0.2.0(ETA. Summer 2023)
- v0.1.0(Jan.7 2020) : Initial Release
- v0.0.1(Dec.29 2019) : Experimental Beta. Most functions wont work yet

Expand Down
1 change: 1 addition & 0 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/caarlos0/env/v9 v9.0.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/denisenkom/go-mssqldb v0.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
Expand Down
3 changes: 3 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9Pq
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/caarlos0/env/v9 v9.0.0 h1:SI6JNsOA+y5gj9njpgybykATIylrRMklbs5ch6wO6pc=
github.com/caarlos0/env/v9 v9.0.0/go.mod h1:ye5mlCVMYh6tZ+vCgrs/B95sj88cg5Tlnc0XIzgZ020=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
Expand Down Expand Up @@ -150,6 +152,7 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc=
github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
Expand Down
89 changes: 38 additions & 51 deletions backend/src/cfg/cfg.go
Original file line number Diff line number Diff line change
@@ -1,70 +1,57 @@
package config

import (
"flag"
"strings"
"github.com/caarlos0/env/v9"
)

"github.com/go-ini/ini"
var (
mapPool = []string{
"de_inferno",
"de_mirage",
"de_nuke",
"de_overpass",
"de_vertigo",
"de_ancient",
"de_anubis",
}
)

// Config Configration Struct for config.ini
type Config struct {
SteamAPIKey string
DefaultPage string
SQLHost string
SQLUser string
SQLPass string
SQLPort int
SQLDBName string
SQLDebugMode bool
HOST string
Cookie string
APIONLY bool
ActiveMapPool []string
ReserveMapPool []string
UserMaxResources UserMaxResources
SteamAPIKey string `env:"STEAM_API_KEY"`
DefaultPage string `env:"DEFAULT_PAGE"`

// Database writing
DBWriteHost string `env:"DB_WRITE_HOST"`
DBWritePort int `env:"DB_WRITE_PORT" envDefault:"3306"`
DBWriteUser string `env:"DB_WRITE_USER"`
DBWritePass string `env:"DB_WRITE_PASS,unset"`
DBWriteName string `env:"DB_WRITE_NAME"`

// Database reading
DBReadHost string `env:"DB_READ_HOST"`
DBReadPort int `env:"DB_READ_PORT" envDefault:"3306"`
DBReadUser string `env:"DB_READ_USER"`
DBReadPass string `env:"DB_READ_PASS,unset"`
DBReadName string `env:"DB_READ_NAME"`

Cookie string `env:"COOKIE"`
APIONLY bool `env:"API_ONLY" envDefault:"false"`
// UserMaxResources UserMaxResources
}

/*
type UserMaxResources struct {
Servers uint16
Teams uint16
Matches uint16
}
*/

var (
// Cnf is configration struct
Cnf Config
ConfigPath *string
)

func init() {
ConfigPath = flag.String("cfg", "config.ini", "path to config.ini")
flag.Parse()
c, err := ini.Load(*ConfigPath)
if err != nil {
func GetConfig() Config {
cfg := Config{}
if err := env.Parse(&cfg); err != nil {
panic(err)
}
active := c.Section("MAPLIST").Key("Active").MustString("de_dust2,de_mirage,de_inferno,de_overpass,de_train,de_nuke,de_vertigo")
reserve := c.Section("MAPLIST").Key("Reserve").MustString("de_cache,de_season")
Cnf = Config{
SteamAPIKey: c.Section("Steam").Key("APIKey").MustString(""),
DefaultPage: c.Section("GET5").Key("DefaultPage").MustString(""),
HOST: c.Section("GET5").Key("HOST").MustString(""),
SQLHost: c.Section("sql").Key("host").MustString(""),
SQLUser: c.Section("sql").Key("user").MustString(""),
SQLPass: c.Section("sql").Key("pass").MustString(""),
SQLPort: c.Section("sql").Key("port").MustInt(3306),
SQLDBName: c.Section("sql").Key("database").MustString(""),
SQLDebugMode: c.Section("sql").Key("debug").MustBool(false),
Cookie: c.Section("GET5").Key("Cookie").MustString("SecretString"),
APIONLY: c.Section("GET5").Key("API_ONLY").MustBool(false),
ActiveMapPool: strings.Split(strings.ToLower(strings.TrimSpace(active)), ","),
ReserveMapPool: strings.Split(strings.ToLower(strings.TrimSpace(reserve)), ","),
UserMaxResources: UserMaxResources{
Servers: uint16(c.Section("USER").Key("Max_Servers").MustUint(10)),
Teams: uint16(c.Section("USER").Key("Max_Teams").MustUint(100)),
Matches: uint16(c.Section("USER").Key("Max_Matches").MustUint(1000)),
},
}

return cfg
}

0 comments on commit 8a49090

Please sign in to comment.