68 lines
2.6 KiB
Go
68 lines
2.6 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type SqlSettings struct {
|
|
DriverName string `json:"DriverName"`
|
|
DataSource string `json:"DataSource"`
|
|
DataSourceReplicas []string `json:"DataSourceReplicas"`
|
|
DataSourceSearchReplicas []string `json:"DataSourceSearchReplicas"`
|
|
MaxIdleConns int `json:"MaxIdleConns"`
|
|
ConnMaxLifetimeMilliseconds int64 `json:"ConnMaxLifetimeMilliseconds"`
|
|
ConnMaxIdleTimeMilliseconds int64 `json:"ConnMaxIdleTimeMilliseconds"`
|
|
MaxOpenConns int `json:"MaxOpenConns"`
|
|
Trace bool `json:"Trace"`
|
|
AtRestEncryptKey string `json:"AtRestEncryptKey"`
|
|
QueryTimeout int `json:"QueryTimeout"`
|
|
DisableDatabaseSearch bool `json:"DisableDatabaseSearch"`
|
|
MigrationsStatementTimeoutSeconds int `json:"MigrationsStatementTimeoutSeconds"`
|
|
ReplicaMonitorIntervalSeconds int `json:"ReplicaMonitorIntervalSeconds"`
|
|
// ReplicaLagSettings []ReplicaLagSetting `json:"ReplicaLagSettings"`
|
|
}
|
|
|
|
type LogSettings struct {
|
|
EnableConsole bool `json:"EnableConsole"`
|
|
ConsoleLevel string `json:"ConsoleLevel"`
|
|
ConsoleJson bool `json:"ConsoleJson"`
|
|
EnableColor bool `json:"EnableColor"`
|
|
EnableFile bool `json:"EnableFile"`
|
|
FileLevel string `json:"FileLevel"`
|
|
FileJson bool `json:"FileJson"`
|
|
FileLocation string `json:"FileLocation"`
|
|
EnableWebhookDebugging bool `json:"EnableWebhookDebugging"`
|
|
EnableDiagnostics bool `json:"EnableDiagnostics"`
|
|
VerboseDiagnostics bool `json:"VerboseDiagnostics"`
|
|
EnableSentry bool `json:"EnableSentry"`
|
|
EnableCaller bool `json:"EnableCaller"`
|
|
AdvancedLoggingConfig string `json:"AdvancedLoggingConfig"`
|
|
MaxFieldSize int `json:"MaxFieldSize"`
|
|
// AdvancedLoggingJSON map[string]interface{} `json:"AdvancedLoggingJSON"`
|
|
}
|
|
|
|
var Conf Config
|
|
|
|
type Config struct {
|
|
SqlSettings SqlSettings `json:"SqlSettings"`
|
|
LogSettings LogSettings `json:"LogSettings"`
|
|
KeycloakSettings KeycloakSettings `json:"KeycloakSettings"`
|
|
}
|
|
|
|
func MustLoad(confPath string) {
|
|
file, err := os.Open(confPath)
|
|
if err != nil {
|
|
log.Fatal("err", "failed to open file")
|
|
}
|
|
defer file.Close()
|
|
|
|
decoder := json.NewDecoder(file)
|
|
if err := decoder.Decode(&Conf); err != nil {
|
|
log.Fatal(err, "failed to decode")
|
|
}
|
|
|
|
log.Println("init config successfully")
|
|
}
|