|
@@ -54,14 +54,11 @@ var (
|
|
|
ApplicationName string
|
|
ApplicationName string
|
|
|
|
|
|
|
|
// Paths
|
|
// Paths
|
|
|
- LogsPath string
|
|
|
|
|
HomePath string
|
|
HomePath string
|
|
|
- DataPath string
|
|
|
|
|
PluginsPath string
|
|
PluginsPath string
|
|
|
CustomInitPath = "conf/custom.ini"
|
|
CustomInitPath = "conf/custom.ini"
|
|
|
|
|
|
|
|
// Log settings.
|
|
// Log settings.
|
|
|
- LogModes []string
|
|
|
|
|
LogConfigs []util.DynMap
|
|
LogConfigs []util.DynMap
|
|
|
|
|
|
|
|
// Http server options
|
|
// Http server options
|
|
@@ -187,11 +184,18 @@ var (
|
|
|
ImageUploadProvider string
|
|
ImageUploadProvider string
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+// TODO move all global vars to this struct
|
|
|
type Cfg struct {
|
|
type Cfg struct {
|
|
|
Raw *ini.File
|
|
Raw *ini.File
|
|
|
|
|
|
|
|
|
|
+ // HTTP Server Settings
|
|
|
|
|
+ AppUrl string
|
|
|
|
|
+ AppSubUrl string
|
|
|
|
|
+
|
|
|
// Paths
|
|
// Paths
|
|
|
ProvisioningPath string
|
|
ProvisioningPath string
|
|
|
|
|
+ DataPath string
|
|
|
|
|
+ LogsPath string
|
|
|
|
|
|
|
|
// SMTP email settings
|
|
// SMTP email settings
|
|
|
Smtp SmtpSettings
|
|
Smtp SmtpSettings
|
|
@@ -411,7 +415,7 @@ func loadSpecifedConfigFile(configFile string, masterFile *ini.File) error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func loadConfiguration(args *CommandLineArgs) (*ini.File, error) {
|
|
|
|
|
|
|
+func (cfg *Cfg) loadConfiguration(args *CommandLineArgs) (*ini.File, error) {
|
|
|
var err error
|
|
var err error
|
|
|
|
|
|
|
|
// load config defaults
|
|
// load config defaults
|
|
@@ -442,7 +446,7 @@ func loadConfiguration(args *CommandLineArgs) (*ini.File, error) {
|
|
|
// load specified config file
|
|
// load specified config file
|
|
|
err = loadSpecifedConfigFile(args.Config, parsedFile)
|
|
err = loadSpecifedConfigFile(args.Config, parsedFile)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- initLogging(parsedFile)
|
|
|
|
|
|
|
+ cfg.initLogging(parsedFile)
|
|
|
log.Fatal(3, err.Error())
|
|
log.Fatal(3, err.Error())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -459,8 +463,8 @@ func loadConfiguration(args *CommandLineArgs) (*ini.File, error) {
|
|
|
evalConfigValues(parsedFile)
|
|
evalConfigValues(parsedFile)
|
|
|
|
|
|
|
|
// update data path and logging config
|
|
// update data path and logging config
|
|
|
- DataPath = makeAbsolute(parsedFile.Section("paths").Key("data").String(), HomePath)
|
|
|
|
|
- initLogging(parsedFile)
|
|
|
|
|
|
|
+ cfg.DataPath = makeAbsolute(parsedFile.Section("paths").Key("data").String(), HomePath)
|
|
|
|
|
+ cfg.initLogging(parsedFile)
|
|
|
|
|
|
|
|
return parsedFile, err
|
|
return parsedFile, err
|
|
|
}
|
|
}
|
|
@@ -517,7 +521,7 @@ func NewCfg() *Cfg {
|
|
|
func (cfg *Cfg) Load(args *CommandLineArgs) error {
|
|
func (cfg *Cfg) Load(args *CommandLineArgs) error {
|
|
|
setHomePath(args)
|
|
setHomePath(args)
|
|
|
|
|
|
|
|
- iniFile, err := loadConfiguration(args)
|
|
|
|
|
|
|
+ iniFile, err := cfg.loadConfiguration(args)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
@@ -538,6 +542,8 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
|
|
|
cfg.ProvisioningPath = makeAbsolute(iniFile.Section("paths").Key("provisioning").String(), HomePath)
|
|
cfg.ProvisioningPath = makeAbsolute(iniFile.Section("paths").Key("provisioning").String(), HomePath)
|
|
|
server := iniFile.Section("server")
|
|
server := iniFile.Section("server")
|
|
|
AppUrl, AppSubUrl = parseAppUrlAndSubUrl(server)
|
|
AppUrl, AppSubUrl = parseAppUrlAndSubUrl(server)
|
|
|
|
|
+ cfg.AppUrl = AppUrl
|
|
|
|
|
+ cfg.AppSubUrl = AppSubUrl
|
|
|
|
|
|
|
|
Protocol = HTTP
|
|
Protocol = HTTP
|
|
|
if server.Key("protocol").MustString("http") == "https" {
|
|
if server.Key("protocol").MustString("http") == "https" {
|
|
@@ -662,7 +668,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
|
|
|
log.Fatal(4, "Invalid callback_url(%s): %s", cfg.RendererCallbackUrl, err)
|
|
log.Fatal(4, "Invalid callback_url(%s): %s", cfg.RendererCallbackUrl, err)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- cfg.ImagesDir = filepath.Join(DataPath, "png")
|
|
|
|
|
|
|
+ cfg.ImagesDir = filepath.Join(cfg.DataPath, "png")
|
|
|
cfg.PhantomDir = filepath.Join(HomePath, "tools/phantomjs")
|
|
cfg.PhantomDir = filepath.Join(HomePath, "tools/phantomjs")
|
|
|
cfg.TempDataLifetime = iniFile.Section("paths").Key("temp_data_lifetime").MustDuration(time.Second * 3600 * 24)
|
|
cfg.TempDataLifetime = iniFile.Section("paths").Key("temp_data_lifetime").MustDuration(time.Second * 3600 * 24)
|
|
|
cfg.MetricsEndpointEnabled = iniFile.Section("metrics").Key("enabled").MustBool(true)
|
|
cfg.MetricsEndpointEnabled = iniFile.Section("metrics").Key("enabled").MustBool(true)
|
|
@@ -720,7 +726,7 @@ func (cfg *Cfg) readSessionConfig() {
|
|
|
SessionOptions.IDLength = 16
|
|
SessionOptions.IDLength = 16
|
|
|
|
|
|
|
|
if SessionOptions.Provider == "file" {
|
|
if SessionOptions.Provider == "file" {
|
|
|
- SessionOptions.ProviderConfig = makeAbsolute(SessionOptions.ProviderConfig, DataPath)
|
|
|
|
|
|
|
+ SessionOptions.ProviderConfig = makeAbsolute(SessionOptions.ProviderConfig, cfg.DataPath)
|
|
|
os.MkdirAll(path.Dir(SessionOptions.ProviderConfig), os.ModePerm)
|
|
os.MkdirAll(path.Dir(SessionOptions.ProviderConfig), os.ModePerm)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -731,15 +737,15 @@ func (cfg *Cfg) readSessionConfig() {
|
|
|
SessionConnMaxLifetime = cfg.Raw.Section("session").Key("conn_max_lifetime").MustInt64(14400)
|
|
SessionConnMaxLifetime = cfg.Raw.Section("session").Key("conn_max_lifetime").MustInt64(14400)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func initLogging(file *ini.File) {
|
|
|
|
|
|
|
+func (cfg *Cfg) initLogging(file *ini.File) {
|
|
|
// split on comma
|
|
// split on comma
|
|
|
- LogModes = strings.Split(file.Section("log").Key("mode").MustString("console"), ",")
|
|
|
|
|
|
|
+ logModes := strings.Split(file.Section("log").Key("mode").MustString("console"), ",")
|
|
|
// also try space
|
|
// also try space
|
|
|
- if len(LogModes) == 1 {
|
|
|
|
|
- LogModes = strings.Split(file.Section("log").Key("mode").MustString("console"), " ")
|
|
|
|
|
|
|
+ if len(logModes) == 1 {
|
|
|
|
|
+ logModes = strings.Split(file.Section("log").Key("mode").MustString("console"), " ")
|
|
|
}
|
|
}
|
|
|
- LogsPath = makeAbsolute(file.Section("paths").Key("logs").String(), HomePath)
|
|
|
|
|
- log.ReadLoggingConfig(LogModes, LogsPath, file)
|
|
|
|
|
|
|
+ cfg.LogsPath = makeAbsolute(file.Section("paths").Key("logs").String(), HomePath)
|
|
|
|
|
+ log.ReadLoggingConfig(logModes, cfg.LogsPath, file)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (cfg *Cfg) LogConfigSources() {
|
|
func (cfg *Cfg) LogConfigSources() {
|
|
@@ -763,8 +769,8 @@ func (cfg *Cfg) LogConfigSources() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
logger.Info("Path Home", "path", HomePath)
|
|
logger.Info("Path Home", "path", HomePath)
|
|
|
- logger.Info("Path Data", "path", DataPath)
|
|
|
|
|
- logger.Info("Path Logs", "path", LogsPath)
|
|
|
|
|
|
|
+ logger.Info("Path Data", "path", cfg.DataPath)
|
|
|
|
|
+ logger.Info("Path Logs", "path", cfg.LogsPath)
|
|
|
logger.Info("Path Plugins", "path", PluginsPath)
|
|
logger.Info("Path Plugins", "path", PluginsPath)
|
|
|
logger.Info("Path Provisioning", "path", cfg.ProvisioningPath)
|
|
logger.Info("Path Provisioning", "path", cfg.ProvisioningPath)
|
|
|
logger.Info("App mode " + Env)
|
|
logger.Info("App mode " + Env)
|