53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package config
|
|
|
|
import "os"
|
|
|
|
type Config struct {
|
|
Port string
|
|
JWTSecret string
|
|
SQLitePath string
|
|
|
|
MySQLHost string
|
|
MySQLPort string
|
|
MySQLUser string
|
|
MySQLPassword string
|
|
|
|
CORSOrigins string
|
|
CORSAllowAll string
|
|
}
|
|
|
|
func Load() Config {
|
|
cfg := Config{
|
|
Port: os.Getenv("PORT"),
|
|
JWTSecret: os.Getenv("JWT_SECRET"),
|
|
SQLitePath: os.Getenv("SQLITE_PATH"),
|
|
|
|
MySQLHost: os.Getenv("MYSQL_HOST"),
|
|
MySQLPort: os.Getenv("MYSQL_PORT"),
|
|
MySQLUser: os.Getenv("MYSQL_USER"),
|
|
MySQLPassword: os.Getenv("MYSQL_PASSWORD"),
|
|
|
|
CORSOrigins: os.Getenv("CORS_ORIGINS"),
|
|
CORSAllowAll: os.Getenv("CORS_ALLOW_ALL"),
|
|
}
|
|
if cfg.JWTSecret == "" {
|
|
cfg.JWTSecret = "dev-secret"
|
|
}
|
|
if cfg.SQLitePath == "" {
|
|
cfg.SQLitePath = "./data/app.db"
|
|
}
|
|
if cfg.MySQLHost == "" {
|
|
cfg.MySQLHost = "127.0.0.1"
|
|
}
|
|
if cfg.MySQLPort == "" {
|
|
cfg.MySQLPort = "3306"
|
|
}
|
|
if cfg.MySQLUser == "" {
|
|
cfg.MySQLUser = "root"
|
|
}
|
|
if cfg.MySQLPassword == "" {
|
|
cfg.MySQLPassword = "root"
|
|
}
|
|
return cfg
|
|
}
|