You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
650 B
Go
46 lines
650 B
Go
package config
|
|
|
|
import (
|
|
"git.phc.dm.unipi.it/phc/website/libs/sl"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
type Config struct {
|
|
Mode string
|
|
Host string
|
|
}
|
|
|
|
var Slot = sl.NewSlot[Config]()
|
|
|
|
func Configure(l *sl.ServiceLocator) (Config, error) {
|
|
m, err := godotenv.Read(".env")
|
|
if err != nil {
|
|
return Config{}, err
|
|
}
|
|
|
|
var cfg Config
|
|
|
|
cfg.Mode = "production"
|
|
if v, ok := m["MODE"]; ok {
|
|
cfg.Mode = v
|
|
}
|
|
|
|
cfg.Host = ":4000"
|
|
if v, ok := m["HOST"]; ok {
|
|
cfg.Host = v
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
var TestingProductionConfig = Config{
|
|
Mode: "production",
|
|
Host: ":4000",
|
|
}
|
|
|
|
var TestingDevelopmentConfig = Config{
|
|
Mode: "development",
|
|
Host: ":4000",
|
|
}
|