[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/).
This commit is contained in:
kim 2024-05-27 15:46:15 +00:00 committed by GitHub
commit 1e7b32490d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
398 changed files with 86174 additions and 684 deletions

View file

@ -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()