sarafu-vise/config/config.go

79 lines
1.5 KiB
Go
Raw Permalink Normal View History

package config
import (
2025-01-18 05:52:08 +01:00
"strings"
apiconfig "git.grassecon.net/grassrootseconomics/sarafu-api/config"
2025-01-18 05:52:08 +01:00
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
"git.grassecon.net/grassrootseconomics/visedriver/env"
)
2025-01-19 17:32:55 +01:00
var (
GetConns = viseconfig.GetConns
2025-01-21 16:43:26 +01:00
EnvPath string
2025-01-19 17:32:55 +01:00
)
2025-01-20 11:28:42 +01:00
func loadEnv() {
if EnvPath == "" {
env.LoadEnvVariables()
} else {
env.LoadEnvVariablesPath(EnvPath)
}
2025-01-12 12:09:47 +01:00
}
const (
2025-01-18 05:52:08 +01:00
defaultSSHHost string = "127.0.0.1"
defaultSSHPort uint = 7122
defaultHTTPHost string = "127.0.0.1"
2025-01-24 05:41:33 +01:00
defaultHTTPPort uint = 7123
2025-01-18 05:52:08 +01:00
defaultDomain = "sarafu.local"
2025-01-12 12:09:47 +01:00
)
func LoadConfig() error {
2025-01-20 11:28:42 +01:00
loadEnv()
err := viseconfig.LoadConfig()
if err != nil {
return err
}
err = apiconfig.LoadConfig()
if err != nil {
return err
}
return nil
}
2025-01-12 12:09:47 +01:00
2025-01-18 05:52:08 +01:00
func SearchDomains() []string {
var ParsedDomains []string
SearchDomains := env.GetEnv("ALIAS_SEARCH_DOMAINS", defaultDomain)
SearchDomainList := strings.Split(env.GetEnv("ALIAS_SEARCH_DOMAINS", SearchDomains), ",")
for _, domain := range SearchDomainList {
ParsedDomains = append(ParsedDomains, strings.ReplaceAll(domain, " ", ""))
}
return ParsedDomains
}
func Language() string {
return viseconfig.DefaultLanguage
}
2025-01-12 12:09:47 +01:00
func Host() string {
return env.GetEnv("HOST", defaultHTTPHost)
2025-01-12 12:09:47 +01:00
}
func Port() uint {
return env.GetEnvUint("PORT", defaultHTTPPort)
2025-01-12 12:09:47 +01:00
}
func HostSSH() string {
return defaultSSHHost
}
func PortSSH() uint {
return defaultSSHPort
}
func ATEndpoint() string {
return env.GetEnv("AT_ENDPOINT", "/")
}