MM-14442: Merge function, to enable merging of configs (#10423)
* MM-14442: Merge function, to enable merging of configs Merge will return a new struct of the same type as base and patch, with patch merged into base. Specifically, patch's values will be preferred except when patch's value is `nil`. Restrictions/guarantees: - base or patch will not be modified - base and patch can be pointers or values - base and patch must be the same type - base and patch must have no unexported types (at the moment) - if maps or slices are different, the entire map or slice will be replaced (at the moment) * License header * major rewrite addressing PR comments from Jesse * MM-14442: merge function for config files - simplified merge for slices and maps - fixed many problems with nested pointers/maps/slices - all references are cloned - 54 new tests, simplified tests for specific problems * MM-14442: fixing formatting, comments
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
372ef87f76
Коммит
498b988a6b
@@ -4,6 +4,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
@@ -140,3 +141,14 @@ func (cs *commonStore) validate(cfg *model.Config) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// mergeConfig merges two configs together. The receiver's values are overwritten with the patch's
|
||||
// values except when the patch's values are nil.
|
||||
func (cs *commonStore) mergeConfig(patch *model.Config) (*model.Config, error) {
|
||||
ret, err := utils.Merge(cs.config, patch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
retC := ret.(model.Config)
|
||||
return &retC, nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user