mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-13 17:17:43 +02:00
fix data race (#1851)
This commit is contained in:
parent
74ac23c980
commit
899076a06a
1 changed files with 10 additions and 0 deletions
|
@ -44,6 +44,7 @@ type Source interface {
|
||||||
|
|
||||||
// A StaticSource always returns the same config. Useful for testing.
|
// A StaticSource always returns the same config. Useful for testing.
|
||||||
type StaticSource struct {
|
type StaticSource struct {
|
||||||
|
mu sync.Mutex
|
||||||
cfg *Config
|
cfg *Config
|
||||||
lis []ChangeListener
|
lis []ChangeListener
|
||||||
}
|
}
|
||||||
|
@ -55,11 +56,17 @@ func NewStaticSource(cfg *Config) *StaticSource {
|
||||||
|
|
||||||
// GetConfig gets the config.
|
// GetConfig gets the config.
|
||||||
func (src *StaticSource) GetConfig() *Config {
|
func (src *StaticSource) GetConfig() *Config {
|
||||||
|
src.mu.Lock()
|
||||||
|
defer src.mu.Unlock()
|
||||||
|
|
||||||
return src.cfg
|
return src.cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetConfig sets the config.
|
// SetConfig sets the config.
|
||||||
func (src *StaticSource) SetConfig(cfg *Config) {
|
func (src *StaticSource) SetConfig(cfg *Config) {
|
||||||
|
src.mu.Lock()
|
||||||
|
defer src.mu.Unlock()
|
||||||
|
|
||||||
src.cfg = cfg
|
src.cfg = cfg
|
||||||
for _, li := range src.lis {
|
for _, li := range src.lis {
|
||||||
li(cfg)
|
li(cfg)
|
||||||
|
@ -68,6 +75,9 @@ func (src *StaticSource) SetConfig(cfg *Config) {
|
||||||
|
|
||||||
// OnConfigChange is ignored for the StaticSource.
|
// OnConfigChange is ignored for the StaticSource.
|
||||||
func (src *StaticSource) OnConfigChange(li ChangeListener) {
|
func (src *StaticSource) OnConfigChange(li ChangeListener) {
|
||||||
|
src.mu.Lock()
|
||||||
|
defer src.mu.Unlock()
|
||||||
|
|
||||||
src.lis = append(src.lis, li)
|
src.lis = append(src.lis, li)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue