72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type config struct {
|
|
AdminPassword string
|
|
Instance string
|
|
Tag string
|
|
|
|
JwtSecret string
|
|
JwtIssuer string
|
|
JwtAudience string
|
|
}
|
|
|
|
var Config *config
|
|
|
|
func Load() *config {
|
|
// Get mastodon instance
|
|
instance := os.Getenv("CAOM_INSTANCE")
|
|
if instance == "" {
|
|
instance = "https://mstdn.party"
|
|
}
|
|
// Get mastodon tag
|
|
tag := os.Getenv("CAOM_TAG")
|
|
if tag == "" {
|
|
tag = "catsofmastodon"
|
|
}
|
|
// Get admin password (Its a single user/admin app so its just fine)
|
|
adminPassword := os.Getenv("CAOM_ADMIN_PASSWORD")
|
|
if adminPassword == "" {
|
|
log.Println("No admin password provided, using default password 'catsaregood'")
|
|
adminPassword = "catsaregood"
|
|
}
|
|
|
|
// Jwt params
|
|
secret := os.Getenv("CAOM_JWT_SECRET")
|
|
if secret == "" {
|
|
log.Fatal("No jwt secret provided")
|
|
}
|
|
issuer := os.Getenv("CAOM_JWT_ISSUER")
|
|
if issuer == "" {
|
|
log.Println("No jwt issuer provided, using default issuer 'CatsOfMastodonBotGo'")
|
|
issuer = "CatsOfMastodonBotGo"
|
|
}
|
|
audience := os.Getenv("CAOM_JWT_AUDIENCE")
|
|
if audience == "" {
|
|
log.Println("No jwt audience provided, using default audience 'CatsOfMastodonBotGo'")
|
|
audience = "CatsOfMastodonBotGo"
|
|
}
|
|
|
|
|
|
// Inititlize AppContext
|
|
var appContext = &config{
|
|
AdminPassword: adminPassword,
|
|
Instance: instance,
|
|
Tag: tag,
|
|
|
|
JwtSecret: secret,
|
|
JwtIssuer: issuer,
|
|
JwtAudience: audience,
|
|
}
|
|
return appContext
|
|
|
|
}
|
|
|
|
func Init() {
|
|
Config = Load()
|
|
}
|