yoake/config/config.go

95 lines
1.4 KiB
Go
Raw Normal View History

2022-11-07 04:45:02 -06:00
package config
import (
2022-11-15 10:31:27 -06:00
"log"
2022-11-07 04:45:02 -06:00
"github.com/jinzhu/configor"
"github.com/labstack/echo/v4/middleware"
)
type C struct {
2022-11-15 10:31:27 -06:00
parsed bool
2022-11-07 04:45:02 -06:00
Hosts map[string]string
Listen struct {
2022-11-11 22:58:05 -06:00
Addr string
AppArmor struct {
Serve string
SSL string
}
Ssl struct {
2022-11-07 04:45:02 -06:00
Use bool
Cert string
Key string
}
}
2022-11-11 16:15:22 -06:00
DB struct {
Badger DBBadger
}
2022-11-19 11:04:03 -06:00
FS FileStore
2022-11-07 04:45:02 -06:00
WebRoot struct {
SiteName string
Root string
SessionKey string
SessionDir string
Secure *middleware.SecureConfig
Log *struct {
Filter []string
Indent bool
}
}
Upstream struct {
Vault struct {
API string
UI string
}
}
Twilio struct {
AccountSid string
AuthToken string
SkipVerify bool
2022-11-10 19:13:09 -06:00
BaseURL string
2022-11-07 04:45:02 -06:00
}
2022-11-11 16:15:22 -06:00
Comm Communication
CanvasLMS CanvasLMS
Auth struct {
2022-11-07 04:45:02 -06:00
ValidMinutes int
2022-11-11 16:15:22 -06:00
DevMode struct {
GrantAll bool
}
Users map[string]struct {
Password string
PublicKeyId []string
Roles []string
2022-11-20 12:05:14 -06:00
Telegram string
2022-11-11 16:15:22 -06:00
}
Yubikey struct {
ClientId string
ClientKey string
2022-11-07 04:45:02 -06:00
}
}
}
var parsedC C
var c C
func Config() C {
2022-11-15 10:31:27 -06:00
if !c.parsed {
log.Panicln("Config() called without calling ParseConfig() first")
}
2022-11-07 04:45:02 -06:00
return c
}
func MockConfig(freshEnv bool, wrapper func(deployedC *C)) {
if freshEnv {
c = parsedC
}
wrapper(&c)
}
func ParseConfig(files ...string) {
configor.Load(&parsedC, files...)
2022-11-15 10:31:27 -06:00
parsedC.parsed = true
2022-11-07 04:45:02 -06:00
c = parsedC
}