summaryrefslogtreecommitdiff
path: root/internal/config/state.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-05-27 15:46:15 +0000
committerLibravatar GitHub <noreply@github.com>2024-05-27 17:46:15 +0200
commit1e7b32490dfdccddd04f46d4b0416b48d749d51b (patch)
tree62a11365933a5a11e0800af64cbdf9172e5e6e7a /internal/config/state.go
parent[chore] Small styling + link issues (#2933) (diff)
downloadgotosocial-1e7b32490dfdccddd04f46d4b0416b48d749d51b.tar.xz
[experiment] add alternative wasm sqlite3 implementation available via build-tag (#2863)
This allows for building GoToSocial with [SQLite transpiled to WASM](https://github.com/ncruces/go-sqlite3) and accessed through [Wazero](https://wazero.io/).
Diffstat (limited to 'internal/config/state.go')
-rw-r--r--internal/config/state.go48
1 files changed, 29 insertions, 19 deletions
diff --git a/internal/config/state.go b/internal/config/state.go
index c55f7b2ec..d01e853a5 100644
--- a/internal/config/state.go
+++ b/internal/config/state.go
@@ -37,25 +37,9 @@ type ConfigState struct { //nolint
// NewState returns a new initialized ConfigState instance.
func NewState() *ConfigState {
- viper := viper.New()
-
- // Flag 'some-flag-name' becomes env var 'GTS_SOME_FLAG_NAME'
- viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
- viper.SetEnvPrefix("gts")
-
- // Load appropriate named vals from env
- viper.AutomaticEnv()
-
- // Create new ConfigState with defaults
- state := &ConfigState{
- viper: viper,
- config: Defaults,
- }
-
- // Perform initial load into viper
- state.reloadToViper()
-
- return state
+ st := new(ConfigState)
+ st.Reset()
+ return st
}
// Config provides safe access to the ConfigState's contained Configuration,
@@ -116,6 +100,32 @@ func (st *ConfigState) Reload() (err error) {
return
}
+// Reset will totally clear
+// ConfigState{}, loading defaults.
+func (st *ConfigState) Reset() {
+ // Do within lock.
+ st.mutex.Lock()
+ defer st.mutex.Unlock()
+
+ // Create new viper.
+ viper := viper.New()
+
+ // Flag 'some-flag-name' becomes env var 'GTS_SOME_FLAG_NAME'
+ viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
+ viper.SetEnvPrefix("gts")
+
+ // Load appropriate
+ // named vals from env.
+ viper.AutomaticEnv()
+
+ // Reset variables.
+ st.viper = viper
+ st.config = Defaults
+
+ // Load into viper.
+ st.reloadToViper()
+}
+
// reloadToViper will reload Configuration{} values into viper.
func (st *ConfigState) reloadToViper() {
raw, err := st.config.MarshalMap()