fix deep copy of config (#1089)

This commit is contained in:
Caleb Doxsey 2020-07-16 21:42:24 -06:00 committed by GitHub
parent d3a7ee38be
commit 02b4e4b619
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 16 deletions

View file

@ -1,12 +1,9 @@
package config
import (
"reflect"
"sync"
"github.com/fsnotify/fsnotify"
"github.com/mitchellh/copystructure"
"github.com/spf13/viper"
)
// Config holds pomerium configuration options.
@ -14,15 +11,13 @@ type Config struct {
Options *Options
}
// Clone creates a deep clone of the config.
// Clone creates a clone of the config.
func (cfg *Config) Clone() *Config {
return copystructure.Must(copystructure.Config{
Copiers: map[reflect.Type]copystructure.CopierFunc{
reflect.TypeOf((*viper.Viper)(nil)): func(i interface{}) (interface{}, error) {
return i, nil
},
},
}.Copy(cfg)).(*Config)
newOptions := new(Options)
*newOptions = *cfg.Options
return &Config{
Options: newOptions,
}
}
// A ChangeListener is called when configuration changes.