79 lines
1.9 KiB
Go
79 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
var Cfg Config
|
|
|
|
type Config struct {
|
|
Debug bool
|
|
ColorizedOutput bool
|
|
Host string
|
|
Port string
|
|
LogManagerServerUrl string
|
|
FolderPaths FolderPaths
|
|
MariaDB MariaDB
|
|
InvexAPI InvexAPI
|
|
}
|
|
|
|
type FolderPaths struct {
|
|
GroupTasksGroups string
|
|
GroupTasksRunningTasks string
|
|
LogsGroupTasks string
|
|
LogsSystem string
|
|
PublicStatic string
|
|
}
|
|
|
|
type MariaDB struct {
|
|
Hostname string
|
|
Port string
|
|
Username string
|
|
Password string
|
|
DatabaseName string
|
|
}
|
|
|
|
type InvexAPI struct {
|
|
Base string
|
|
Token string
|
|
}
|
|
|
|
func LoadConfig() {
|
|
// used to determine server was startet in docker or not
|
|
if os.Getenv("DOCKER") == "" {
|
|
fmt.Println("Load env from file")
|
|
godotenv.Load(".env")
|
|
} else {
|
|
fmt.Println("Load env from system")
|
|
}
|
|
|
|
Cfg = Config{
|
|
Debug: os.Getenv("DEBUG") == "true",
|
|
ColorizedOutput: os.Getenv("COLORIZED_OUTPUT") == "true",
|
|
Host: os.Getenv("HOST"),
|
|
Port: os.Getenv("PORT"),
|
|
LogManagerServerUrl: os.Getenv("LOG_MANAGER_SERVER_URL"),
|
|
FolderPaths: FolderPaths{
|
|
GroupTasksGroups: os.Getenv("FOLDER_GROUPTASKS_GROUPS"),
|
|
GroupTasksRunningTasks: os.Getenv("FOLDER_GROUPTASKS_RUNNINGTASKS"),
|
|
LogsGroupTasks: os.Getenv("FOLDER_LOGS_GROUPTASKS"),
|
|
LogsSystem: os.Getenv("FOLDER_LOGS_SYSTEM"),
|
|
PublicStatic: os.Getenv("FOLDER_PUBLIC_STATIC"),
|
|
},
|
|
MariaDB: MariaDB{
|
|
Hostname: os.Getenv("MARIADB_HOSTNAME"),
|
|
Port: os.Getenv("MARIADB_PORT"),
|
|
Username: os.Getenv("MARIADB_USERNAME"),
|
|
Password: os.Getenv("MARIADB_PASSWORD"),
|
|
DatabaseName: os.Getenv("MARIADB_DATABASE_NAME"),
|
|
},
|
|
InvexAPI: InvexAPI{
|
|
Base: os.Getenv("INVEX_API_BASE"),
|
|
Token: os.Getenv("INVEX_API_TOKEN"),
|
|
},
|
|
}
|
|
}
|