summaryrefslogtreecommitdiffstats
path: root/modules/setting/setting.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-05-04 11:55:35 +0800
committerGitHub <noreply@github.com>2023-05-04 11:55:35 +0800
commit377a0a20f01a62f15a1504a3bba6cf6cc0c98bea (patch)
treee86a1818f23be1605a4cd707fadc7dcdce546d18 /modules/setting/setting.go
parenta2fe68e50ba819daed9b0e28166a749d18c58750 (diff)
downloadgitea-377a0a20f01a62f15a1504a3bba6cf6cc0c98bea.tar.gz
gitea-377a0a20f01a62f15a1504a3bba6cf6cc0c98bea.zip
Merge setting.InitXXX into one function with options (#24389)
This PR will merge 3 Init functions on setting packages as 1 and introduce an options struct.
Diffstat (limited to 'modules/setting/setting.go')
-rw-r--r--modules/setting/setting.go41
1 files changed, 7 insertions, 34 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 9ab55e91c5..b085a7b321 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -15,7 +15,6 @@ import (
"strings"
"time"
- "code.gitea.io/gitea/modules/auth/password/hash"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/user"
)
@@ -203,44 +202,18 @@ func PrepareAppDataPath() error {
return nil
}
-// InitProviderFromExistingFile initializes config provider from an existing config file (app.ini)
-func InitProviderFromExistingFile() {
- var err error
- CfgProvider, err = newConfigProviderFromFile(CustomConf, false, "")
- if err != nil {
- log.Fatal("InitProviderFromExistingFile: %v", err)
- }
-}
-
-// InitProviderAllowEmpty initializes config provider from file, it's also fine that if the config file (app.ini) doesn't exist
-func InitProviderAllowEmpty() {
- var err error
- CfgProvider, err = newConfigProviderFromFile(CustomConf, true, "")
- if err != nil {
- log.Fatal("InitProviderAllowEmpty: %v", err)
+func Init(opts *Options) {
+ if opts.CustomConf == "" {
+ opts.CustomConf = CustomConf
}
-}
-
-// InitProviderAndLoadCommonSettingsForTest initializes config provider and load common setttings for tests
-func InitProviderAndLoadCommonSettingsForTest(extraConfigs ...string) {
var err error
- CfgProvider, err = newConfigProviderFromFile(CustomConf, true, strings.Join(extraConfigs, "\n"))
+ CfgProvider, err = newConfigProviderFromFile(opts)
if err != nil {
- log.Fatal("InitProviderAndLoadCommonSettingsForTest: %v", err)
+ log.Fatal("Init[%v]: %v", opts, err)
}
- loadCommonSettingsFrom(CfgProvider)
- if err := PrepareAppDataPath(); err != nil {
- log.Fatal("Can not prepare APP_DATA_PATH: %v", err)
+ if !opts.DisableLoadCommonSettings {
+ loadCommonSettingsFrom(CfgProvider)
}
- // register the dummy hash algorithm function used in the test fixtures
- _ = hash.Register("dummy", hash.NewDummyHasher)
-
- PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy")
-}
-
-// LoadCommonSettings loads common configurations from a configuration provider.
-func LoadCommonSettings() {
- loadCommonSettingsFrom(CfgProvider)
}
// loadCommonSettingsFrom loads common configurations from a configuration provider.