2022-11-13 19:17:07 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2022-11-21 22:52:44 +01:00
|
|
|
"fmt"
|
2022-12-07 22:11:44 +01:00
|
|
|
"github.com/rs/zerolog"
|
2022-11-13 19:17:07 +01:00
|
|
|
"github.com/rs/zerolog/log"
|
2022-12-16 01:07:48 +01:00
|
|
|
"gogs.mikescher.com/BlackForestBytes/goext/confext"
|
2022-11-13 19:17:07 +01:00
|
|
|
"os"
|
2022-11-18 21:25:40 +01:00
|
|
|
"time"
|
2022-11-13 19:17:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2022-11-25 22:42:21 +01:00
|
|
|
Namespace string
|
2022-12-07 23:32:58 +01:00
|
|
|
BaseURL string `env:"SCN_URL"`
|
|
|
|
GinDebug bool `env:"SCN_GINDEBUG"`
|
|
|
|
LogLevel zerolog.Level `env:"SCN_LOGLEVEL"`
|
|
|
|
ServerIP string `env:"SCN_IP"`
|
|
|
|
ServerPort string `env:"SCN_PORT"`
|
2023-01-06 00:39:21 +01:00
|
|
|
DBMain DBConfig `envprefix:"SCN_DB_MAIN_"`
|
|
|
|
DBRequests DBConfig `envprefix:"SCN_DB_REQUESTS_"`
|
|
|
|
DBLogs DBConfig `envprefix:"SCN_DB_LOGS_"`
|
2022-12-07 23:32:58 +01:00
|
|
|
RequestTimeout time.Duration `env:"SCN_REQUEST_TIMEOUT"`
|
2022-12-20 09:52:33 +01:00
|
|
|
RequestMaxRetry int `env:"SCN_REQUEST_MAXRETRY"`
|
|
|
|
RequestRetrySleep time.Duration `env:"SCN_REQUEST_RETRYSLEEP"`
|
2023-01-06 00:39:21 +01:00
|
|
|
Cors bool `env:"SCN_CORS"`
|
2022-12-07 23:32:58 +01:00
|
|
|
ReturnRawErrors bool `env:"SCN_ERROR_RETURN"`
|
|
|
|
DummyFirebase bool `env:"SCN_DUMMY_FB"`
|
|
|
|
DummyGoogleAPI bool `env:"SCN_DUMMY_GOOG"`
|
2022-12-14 18:46:26 +01:00
|
|
|
FirebaseTokenURI string `env:"SCN_FB_TOKENURI"`
|
|
|
|
FirebaseProjectID string `env:"SCN_FB_PROJECTID"`
|
|
|
|
FirebasePrivKeyID string `env:"SCN_FB_PRIVATEKEYID"`
|
|
|
|
FirebaseClientMail string `env:"SCN_FB_CLIENTEMAIL"`
|
|
|
|
FirebasePrivateKey string `env:"SCN_FB_PRIVATEKEY"`
|
|
|
|
GoogleAPITokenURI string `env:"SCN_GOOG_TOKENURI"`
|
|
|
|
GoogleAPIPrivKeyID string `env:"SCN_GOOG_PRIVATEKEYID"`
|
|
|
|
GoogleAPIClientMail string `env:"SCN_GOOG_CLIENTEMAIL"`
|
|
|
|
GoogleAPIPrivateKey string `env:"SCN_GOOG_PRIVATEKEY"`
|
|
|
|
GooglePackageName string `env:"SCN_GOOG_PACKAGENAME"`
|
|
|
|
GoogleProProductID string `env:"SCN_GOOG_PROPRODUCTID"`
|
2023-01-06 00:39:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type DBConfig struct {
|
|
|
|
File string `env:"FILE"`
|
|
|
|
Journal string `env:"JOURNAL"`
|
|
|
|
Timeout time.Duration `env:"TIMEOUT"`
|
|
|
|
MaxOpenConns int `env:"MAXOPENCONNECTIONS"`
|
|
|
|
MaxIdleConns int `env:"MAXIDLECONNECTIONS"`
|
|
|
|
ConnMaxLifetime time.Duration `env:"CONNEXTIONMAXLIFETIME"`
|
|
|
|
ConnMaxIdleTime time.Duration `env:"CONNEXTIONMAXIDLETIME"`
|
|
|
|
CheckForeignKeys bool `env:"CHECKFOREIGNKEYS"`
|
|
|
|
SingleConn bool `env:"SINGLECONNECTION"`
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var Conf Config
|
|
|
|
|
2022-11-23 19:32:23 +01:00
|
|
|
var configLocHost = func() Config {
|
|
|
|
return Config{
|
2023-01-06 00:39:21 +01:00
|
|
|
Namespace: "local-host",
|
|
|
|
BaseURL: "http://localhost:8080",
|
|
|
|
GinDebug: false,
|
|
|
|
LogLevel: zerolog.DebugLevel,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "8080",
|
|
|
|
DBMain: DBConfig{
|
|
|
|
File: ".run-data/loc_main.sqlite3",
|
|
|
|
Journal: "WAL",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBRequests: DBConfig{
|
|
|
|
File: ".run-data/loc_requests.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBLogs: DBConfig{
|
|
|
|
File: ".run-data/loc_logs.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
2022-11-25 22:42:21 +01:00
|
|
|
RequestTimeout: 16 * time.Second,
|
2022-12-20 09:52:33 +01:00
|
|
|
RequestMaxRetry: 8,
|
|
|
|
RequestRetrySleep: 100 * time.Millisecond,
|
2022-11-25 22:42:21 +01:00
|
|
|
ReturnRawErrors: true,
|
|
|
|
DummyFirebase: true,
|
|
|
|
FirebaseTokenURI: "",
|
|
|
|
FirebaseProjectID: "",
|
|
|
|
FirebasePrivKeyID: "",
|
|
|
|
FirebaseClientMail: "",
|
|
|
|
FirebasePrivateKey: "",
|
|
|
|
DummyGoogleAPI: true,
|
|
|
|
GoogleAPITokenURI: "",
|
|
|
|
GoogleAPIPrivKeyID: "",
|
|
|
|
GoogleAPIClientMail: "",
|
|
|
|
GoogleAPIPrivateKey: "",
|
|
|
|
GooglePackageName: "",
|
|
|
|
GoogleProProductID: "",
|
2022-12-20 09:22:18 +01:00
|
|
|
Cors: true,
|
2022-11-23 19:32:23 +01:00
|
|
|
}
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
2022-11-23 19:32:23 +01:00
|
|
|
var configLocDocker = func() Config {
|
|
|
|
return Config{
|
2023-01-06 00:39:21 +01:00
|
|
|
Namespace: "local-docker",
|
|
|
|
BaseURL: "http://localhost:8080",
|
|
|
|
GinDebug: false,
|
|
|
|
LogLevel: zerolog.DebugLevel,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "80",
|
|
|
|
DBMain: DBConfig{
|
|
|
|
File: "/data/docker_scn_main.sqlite3",
|
|
|
|
Journal: "WAL",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBRequests: DBConfig{
|
|
|
|
File: "/data/docker_scn_requests.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBLogs: DBConfig{
|
|
|
|
File: "/data/docker_scn_logs.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
2022-11-25 22:42:21 +01:00
|
|
|
RequestTimeout: 16 * time.Second,
|
2022-12-20 09:52:33 +01:00
|
|
|
RequestMaxRetry: 8,
|
|
|
|
RequestRetrySleep: 100 * time.Millisecond,
|
2022-11-25 22:42:21 +01:00
|
|
|
ReturnRawErrors: true,
|
|
|
|
DummyFirebase: true,
|
|
|
|
FirebaseTokenURI: "",
|
|
|
|
FirebaseProjectID: "",
|
|
|
|
FirebasePrivKeyID: "",
|
|
|
|
FirebaseClientMail: "",
|
|
|
|
FirebasePrivateKey: "",
|
|
|
|
DummyGoogleAPI: true,
|
|
|
|
GoogleAPITokenURI: "",
|
|
|
|
GoogleAPIPrivKeyID: "",
|
|
|
|
GoogleAPIClientMail: "",
|
|
|
|
GoogleAPIPrivateKey: "",
|
|
|
|
GooglePackageName: "",
|
|
|
|
GoogleProProductID: "",
|
2022-12-20 09:22:18 +01:00
|
|
|
Cors: true,
|
2022-11-23 19:32:23 +01:00
|
|
|
}
|
2022-11-20 03:41:38 +01:00
|
|
|
}
|
|
|
|
|
2022-11-23 19:32:23 +01:00
|
|
|
var configDev = func() Config {
|
|
|
|
return Config{
|
2023-01-06 00:39:21 +01:00
|
|
|
Namespace: "develop",
|
|
|
|
BaseURL: confEnv("SCN_URL"),
|
|
|
|
GinDebug: false,
|
|
|
|
LogLevel: zerolog.DebugLevel,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "80",
|
|
|
|
DBMain: DBConfig{
|
|
|
|
File: "/data/scn_main.sqlite3",
|
|
|
|
Journal: "WAL",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBRequests: DBConfig{
|
|
|
|
File: "/data/scn_requests.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBLogs: DBConfig{
|
|
|
|
File: "/data/scn_logs.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
2022-11-25 22:42:21 +01:00
|
|
|
RequestTimeout: 16 * time.Second,
|
2022-12-20 09:52:33 +01:00
|
|
|
RequestMaxRetry: 8,
|
|
|
|
RequestRetrySleep: 100 * time.Millisecond,
|
2022-11-25 22:42:21 +01:00
|
|
|
ReturnRawErrors: true,
|
|
|
|
DummyFirebase: false,
|
|
|
|
FirebaseTokenURI: "https://oauth2.googleapis.com/token",
|
2022-12-14 18:46:26 +01:00
|
|
|
FirebaseProjectID: confEnv("SCN_FB_PROJECTID"),
|
|
|
|
FirebasePrivKeyID: confEnv("SCN_FB_PRIVATEKEYID"),
|
|
|
|
FirebaseClientMail: confEnv("SCN_FB_CLIENTEMAIL"),
|
|
|
|
FirebasePrivateKey: confEnv("SCN_FB_PRIVATEKEY"),
|
2022-11-25 22:42:21 +01:00
|
|
|
DummyGoogleAPI: false,
|
|
|
|
GoogleAPITokenURI: "https://oauth2.googleapis.com/token",
|
2022-12-14 18:46:26 +01:00
|
|
|
GoogleAPIPrivKeyID: confEnv("SCN_GOOG_PRIVATEKEYID"),
|
|
|
|
GoogleAPIClientMail: confEnv("SCN_GOOG_CLIENTEMAIL"),
|
|
|
|
GoogleAPIPrivateKey: confEnv("SCN_GOOG_PRIVATEKEY"),
|
|
|
|
GooglePackageName: confEnv("SCN_GOOG_PACKAGENAME"),
|
|
|
|
GoogleProProductID: confEnv("SCN_GOOG_PROPRODUCTID"),
|
2022-12-20 09:22:18 +01:00
|
|
|
Cors: true,
|
2022-11-23 19:32:23 +01:00
|
|
|
}
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
2022-11-23 19:32:23 +01:00
|
|
|
var configStag = func() Config {
|
|
|
|
return Config{
|
2023-01-06 00:39:21 +01:00
|
|
|
Namespace: "staging",
|
|
|
|
BaseURL: confEnv("SCN_URL"),
|
|
|
|
GinDebug: false,
|
|
|
|
LogLevel: zerolog.DebugLevel,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "80",
|
|
|
|
DBMain: DBConfig{
|
|
|
|
File: "/data/scn_main.sqlite3",
|
|
|
|
Journal: "WAL",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBRequests: DBConfig{
|
|
|
|
File: "/data/scn_requests.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBLogs: DBConfig{
|
|
|
|
File: "/data/scn_logs.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
2022-11-25 22:42:21 +01:00
|
|
|
RequestTimeout: 16 * time.Second,
|
2022-12-20 09:52:33 +01:00
|
|
|
RequestMaxRetry: 8,
|
|
|
|
RequestRetrySleep: 100 * time.Millisecond,
|
2022-11-25 22:42:21 +01:00
|
|
|
ReturnRawErrors: true,
|
|
|
|
DummyFirebase: false,
|
|
|
|
FirebaseTokenURI: "https://oauth2.googleapis.com/token",
|
2022-12-14 18:46:26 +01:00
|
|
|
FirebaseProjectID: confEnv("SCN_FB_PROJECTID"),
|
|
|
|
FirebasePrivKeyID: confEnv("SCN_FB_PRIVATEKEYID"),
|
|
|
|
FirebaseClientMail: confEnv("SCN_FB_CLIENTEMAIL"),
|
|
|
|
FirebasePrivateKey: confEnv("SCN_FB_PRIVATEKEY"),
|
2022-11-25 22:42:21 +01:00
|
|
|
DummyGoogleAPI: false,
|
|
|
|
GoogleAPITokenURI: "https://oauth2.googleapis.com/token",
|
2022-12-14 18:46:26 +01:00
|
|
|
GoogleAPIPrivKeyID: confEnv("SCN_GOOG_PRIVATEKEYID"),
|
|
|
|
GoogleAPIClientMail: confEnv("SCN_GOOG_CLIENTEMAIL"),
|
|
|
|
GoogleAPIPrivateKey: confEnv("SCN_GOOG_PRIVATEKEY"),
|
|
|
|
GooglePackageName: confEnv("SCN_GOOG_PACKAGENAME"),
|
|
|
|
GoogleProProductID: confEnv("SCN_GOOG_PROPRODUCTID"),
|
2022-12-20 09:22:18 +01:00
|
|
|
Cors: true,
|
2022-11-23 19:32:23 +01:00
|
|
|
}
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
2022-11-23 19:32:23 +01:00
|
|
|
var configProd = func() Config {
|
|
|
|
return Config{
|
2023-01-06 00:39:21 +01:00
|
|
|
Namespace: "production",
|
|
|
|
BaseURL: confEnv("SCN_URL"),
|
|
|
|
GinDebug: false,
|
|
|
|
LogLevel: zerolog.InfoLevel,
|
|
|
|
ServerIP: "0.0.0.0",
|
|
|
|
ServerPort: "80",
|
|
|
|
DBMain: DBConfig{
|
|
|
|
File: "/data/scn_main.sqlite3",
|
|
|
|
Journal: "WAL",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBRequests: DBConfig{
|
|
|
|
File: "/data/scn_requests.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
|
|
|
DBLogs: DBConfig{
|
|
|
|
File: "/data/scn_logs.sqlite3",
|
|
|
|
Journal: "DELETE",
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
CheckForeignKeys: false,
|
|
|
|
SingleConn: false,
|
|
|
|
MaxOpenConns: 5,
|
|
|
|
MaxIdleConns: 5,
|
|
|
|
ConnMaxLifetime: 60 * time.Minute,
|
|
|
|
ConnMaxIdleTime: 60 * time.Minute,
|
|
|
|
},
|
2022-11-25 22:42:21 +01:00
|
|
|
RequestTimeout: 16 * time.Second,
|
2022-12-20 09:52:33 +01:00
|
|
|
RequestMaxRetry: 8,
|
|
|
|
RequestRetrySleep: 100 * time.Millisecond,
|
2022-11-25 22:42:21 +01:00
|
|
|
ReturnRawErrors: false,
|
|
|
|
DummyFirebase: false,
|
|
|
|
FirebaseTokenURI: "https://oauth2.googleapis.com/token",
|
2022-12-14 18:46:26 +01:00
|
|
|
FirebaseProjectID: confEnv("SCN_SCN_FB_PROJECTID"),
|
|
|
|
FirebasePrivKeyID: confEnv("SCN_SCN_FB_PRIVATEKEYID"),
|
|
|
|
FirebaseClientMail: confEnv("SCN_SCN_FB_CLIENTEMAIL"),
|
|
|
|
FirebasePrivateKey: confEnv("SCN_SCN_FB_PRIVATEKEY"),
|
2022-11-25 22:42:21 +01:00
|
|
|
DummyGoogleAPI: false,
|
|
|
|
GoogleAPITokenURI: "https://oauth2.googleapis.com/token",
|
2022-12-14 18:46:26 +01:00
|
|
|
GoogleAPIPrivKeyID: confEnv("SCN_SCN_GOOG_PRIVATEKEYID"),
|
|
|
|
GoogleAPIClientMail: confEnv("SCN_SCN_GOOG_CLIENTEMAIL"),
|
|
|
|
GoogleAPIPrivateKey: confEnv("SCN_SCN_GOOG_PRIVATEKEY"),
|
|
|
|
GooglePackageName: confEnv("SCN_SCN_GOOG_PACKAGENAME"),
|
|
|
|
GoogleProProductID: confEnv("SCN_SCN_GOOG_PROPRODUCTID"),
|
2022-12-20 09:22:18 +01:00
|
|
|
Cors: true,
|
2022-11-23 19:32:23 +01:00
|
|
|
}
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
2022-11-23 19:32:23 +01:00
|
|
|
var allConfig = map[string]func() Config{
|
|
|
|
"local-host": configLocHost,
|
|
|
|
"local-docker": configLocDocker,
|
|
|
|
"develop": configDev,
|
|
|
|
"staging": configStag,
|
|
|
|
"production": configProd,
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
2023-01-06 00:39:21 +01:00
|
|
|
func GetConfig(ns string) (Config, bool) {
|
2022-11-13 19:17:07 +01:00
|
|
|
if ns == "" {
|
2022-12-07 23:32:58 +01:00
|
|
|
ns = "local-host"
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
2022-12-07 23:32:58 +01:00
|
|
|
if cfn, ok := allConfig[ns]; ok {
|
|
|
|
c := cfn()
|
2022-12-16 01:07:48 +01:00
|
|
|
err := confext.ApplyEnvOverrides(&c)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-12-07 23:32:58 +01:00
|
|
|
return c, true
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
return Config{}, false
|
|
|
|
}
|
|
|
|
|
2022-11-21 22:52:44 +01:00
|
|
|
func confEnv(key string) string {
|
|
|
|
if v, ok := os.LookupEnv(key); ok {
|
|
|
|
return v
|
|
|
|
} else {
|
2022-11-26 17:03:26 +01:00
|
|
|
log.Fatal().Msg(fmt.Sprintf("Missing required environment variable '%s'", key))
|
|
|
|
return ""
|
2022-11-21 22:52:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-13 19:17:07 +01:00
|
|
|
func init() {
|
2022-12-14 18:46:26 +01:00
|
|
|
ns := os.Getenv("SCN_NAMESPACE")
|
2022-11-13 19:17:07 +01:00
|
|
|
|
2023-01-06 00:39:21 +01:00
|
|
|
cfg, ok := GetConfig(ns)
|
2022-11-13 19:17:07 +01:00
|
|
|
if !ok {
|
|
|
|
log.Fatal().Str("ns", ns).Msg("Unknown config-namespace")
|
|
|
|
}
|
|
|
|
|
|
|
|
Conf = cfg
|
|
|
|
}
|