This repository has been archived on 2021-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
2019-04-02 14:28:06 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type config struct {
|
|
|
|
port string
|
|
|
|
dnt bool
|
|
|
|
dbPath string
|
|
|
|
statsAuth bool
|
|
|
|
statsUsername string
|
|
|
|
statsPassword string
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
appConfig = &config{}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
appConfig.port = port()
|
|
|
|
appConfig.dnt = dnt()
|
|
|
|
appConfig.dbPath = dbPath()
|
|
|
|
appConfig.statsUsername = statsUsername()
|
|
|
|
appConfig.statsPassword = statsPassword()
|
2019-04-03 14:51:44 +00:00
|
|
|
appConfig.statsAuth = statsAuth(appConfig)
|
2019-04-02 14:28:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func port() string {
|
|
|
|
port := os.Getenv("PORT")
|
|
|
|
if len(port) != 0 {
|
|
|
|
return port
|
|
|
|
} else {
|
|
|
|
return "8080"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func dnt() bool {
|
|
|
|
dnt := os.Getenv("DNT")
|
|
|
|
dntBool, e := strconv.ParseBool(dnt)
|
|
|
|
if e != nil {
|
|
|
|
dntBool = true
|
|
|
|
}
|
|
|
|
return dntBool
|
|
|
|
}
|
|
|
|
|
|
|
|
func dbPath() (dbPath string) {
|
|
|
|
dbPath = os.Getenv("DB_PATH")
|
|
|
|
if len(dbPath) == 0 {
|
|
|
|
dbPath = "data/kis3.db"
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func statsUsername() (username string) {
|
|
|
|
username = os.Getenv("STATS_USERNAME")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func statsPassword() (password string) {
|
|
|
|
password = os.Getenv("STATS_PASSWORD")
|
|
|
|
return
|
|
|
|
}
|
2019-04-03 14:51:44 +00:00
|
|
|
|
|
|
|
func statsAuth(ac *config) bool {
|
|
|
|
return len(ac.statsUsername) > 0 && len(ac.statsPassword) > 0
|
|
|
|
}
|