package config import ( "encoding/json" "fmt" "os" "path/filepath" ) const ( configDir string = "./config/" configFileName string = "services.json" ) type Config struct { RootDomain string `json:"rootDomain"` FlowGID int32 `json:"flowGID"` Docker Docker `json:"docker"` Traefik Traefik `json:"traefik"` Forgejo Forgejo `json:"forgejo"` GoToSocial Gotosocial `json:"gotosocial"` Woodpecker Woodpecker `json:"woodpecker"` Landing LandingPage `json:"landing"` } type Docker struct { Host string `json:"host"` Network DockerNetwork `json:"network"` } type DockerNetwork struct { Name string `json:"name"` Subnet string `json:"subnet"` } type Traefik struct { Version string `json:"version"` CheckNewVersion bool `json:"checkNewVersion"` ExternalSSHPort int32 `json:"externalSSHPort"` LogLevel string `json:"logLevel"` SendAnonymousUsage bool `json:"sendAnonymousUsage"` ContainerName string `json:"containerName"` ContainerIpv4Address string `json:"containerIpv4Address"` GenerateAcmeCertificates bool `json:"generateAcmeCertificates"` AcmeEmail string `json:"acmeEmail"` SharedMountPoint string `json:"sharedMountPoint"` TlsHostDirectory string `json:"tlsHostDirectory"` TlsContainerDirectory string `json:"tlsContainerDirectory"` StaticConfigDirectory string `json:"staticConfigDirectory"` DynamicConfigDirectory string `json:"dynamicConfigDirectory"` } type Forgejo struct { Version string `json:"version"` Name string `json:"name"` Subdomain string `json:"subdomain"` ContainerName string `json:"containerName"` ContainerIpv4Address string `json:"containerIpv4Address"` SshPort int32 `json:"sshPort"` HttpPort int32 `json:"httpPort"` RunMode string `json:"runMode"` LogLevel string `json:"logLevel"` LinuxUID int32 `json:"linuxUID"` DataHostDirectory string `json:"dataHostDirectory"` DataContainerDirectory string `json:"dataContainerDirectory"` Home string `json:"home"` Work string `json:"work"` Custom string `json:"custom"` AppIni string `json:"appIni"` Bin string `json:"bin"` Tmp string `json:"tmp"` SecretHostDirectory string `json:"secretHostDirectory"` SecretContainerDirectory string `json:"secretContainerDirectory"` SecretKey string `json:"secretKey"` InternalToken string `json:"internalToken"` LfsJwtSecret string `json:"lfsJwtSecret"` Oauth2Enable bool `json:"oauth2Enable"` Oauth2JwtSigningAlgo string `json:"oauth2JwtSigningAlgo"` Oauth2JwtSecret string `json:"oauth2JwtSecret"` Actions ForgejoActions `json:"actions"` } type ForgejoActions struct { Enabled bool `json:"enabled"` DefaultActionsURL string `json:"defaultActionsURL"` } type Gotosocial struct { Version string `json:"version"` Name string `json:"name"` LogLevel string `json:"logLevel"` LinuxUID int32 `json:"linuxUID"` Subdomain string `json:"subdomain"` ContainerName string `json:"containerName"` ContainerIpv4Address string `json:"containerIpv4Address"` Port int32 `json:"port"` DataHostDirectory string `json:"dataHostDirectory"` DataContainerDirectory string `json:"dataContainerDirectory"` AccountsRegistrationOpen bool `json:"accountsRegistrationOpen"` AccountsAllowCustomCss bool `json:"accountsAllowCustomCss"` LandingPageUser string `json:"landingPageUser"` WebBaseDirectory string `json:"webBaseDirectory"` TZ string `json:"tz"` } type Woodpecker struct { Version string `json:"version"` LogLevel string `json:"logLevel"` LinuxUID int32 `json:"linuxUID"` Subdomain string `json:"subdomain"` GrpcSubdomain string `json:"grpcSubdomain"` ContainerName string `json:"containerName"` ContainerIpv4Address string `json:"containerIpv4Address"` HttpPort int32 `json:"httpPort"` GrpcPort int32 `json:"grpcPort"` DataHostDirectory string `json:"dataHostDirectory"` DataContainerDirectory string `json:"dataContainerDirectory"` Admin string `json:"admin"` Open bool `json:"open"` AgentSecret string `json:"agentSecret"` ForgejoClientID string `json:"forgejoClientID"` ForgejoClientSecret string `json:"forgejoClientSecret"` } type LandingPage struct { Version string `json:"version"` ContainerName string `json:"containerName"` ContainerIpv4Address string `json:"containerIpv4Address"` Services []LandingPageLinks `json:"services"` Profiles []LandingPageLinks `json:"profiles"` Port int32 `json:"port"` ImageDigest string `json:"imageDigest"` } type LandingPageLinks struct { Title string `json:"title"` URL string `json:"url"` Rel string `json:"rel"` } func NewConfig(environment string) (Config, error) { var c Config path := filepath.Join(configDir, environment, configFileName) f, err := os.Open(path) if err != nil { return c, fmt.Errorf("unable to open the file; %w", err) } defer f.Close() decoder := json.NewDecoder(f) if err = decoder.Decode(&c); err != nil { return c, fmt.Errorf("unable to decode JSON data; %w", err) } return c, nil }