mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* MM-14145: The config store Set will now Save automatically When UpdateConfig (and configStore.Set) is called in admin.go and config.go, commonStore.Set now takes a store-specific persist function. It uses that persist function to save the configuration automatically. Removed: Now callers do not have to call configStore.Save or app.PersistConfig, and those functions have been removed. Possible downside: this means a "failed to persist config" error can now be thrown during a app.UpdateConfig or commonStore.Set call. But considering application code never really sets a config without saving it (except in the test cases, which were testing that -- see below), it seems fine to group these responsibilities. Also removed: tests for 'set without save'. Since that can not happen anymore, the tests are not needed. * Removed Save completely, cleaned up formatting, joined save test with set tests. * fixed shadowed variable error
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package config
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/mattermost/mattermost-server/model"
|
|
)
|
|
|
|
// Listener is a callback function invoked when the configuration changes.
|
|
type Listener func(oldConfig *model.Config, newConfig *model.Config)
|
|
|
|
// Store abstracts the act of getting and setting the configuration.
|
|
type Store interface {
|
|
// Get fetches the current, cached configuration.
|
|
Get() *model.Config
|
|
|
|
// GetEnvironmentOverrides fetches the configuration fields overridden by environment variables.
|
|
GetEnvironmentOverrides() map[string]interface{}
|
|
|
|
// Set replaces the current configuration in its entirety and updates the backing store.
|
|
Set(*model.Config) (*model.Config, error)
|
|
|
|
// Load updates the current configuration from the backing store, possibly initializing.
|
|
Load() (err error)
|
|
|
|
// AddListener adds a callback function to invoke when the configuration is modified.
|
|
AddListener(listener Listener) string
|
|
|
|
// RemoveListener removes a callback function using an id returned from AddListener.
|
|
RemoveListener(id string)
|
|
|
|
// String describes the backing store for the config.
|
|
String() string
|
|
|
|
// Close cleans up resources associated with the store.
|
|
Close() error
|
|
}
|
|
|
|
// NewStore creates a database or file store given a data source name by which to connect.
|
|
func NewStore(dsn string, watch bool) (Store, error) {
|
|
if strings.HasPrefix(dsn, "mysql://") || strings.HasPrefix(dsn, "postgres://") {
|
|
return NewDatabaseStore(dsn)
|
|
}
|
|
|
|
return NewFileStore(dsn, watch)
|
|
}
|