Skip to content

Commit 9df2d7f

Browse files
chore: simplify init functions (#863)
This commit removes the init() function which initializes the `providerFactories` variable. This mechanism is fragile because it assumes that no other init() function will call `onboardNewProvider()` before the map is initialized. In practice the Go compiler evaluates the init() functions from a single package in lexical filename order meaning that we could have a Go file evaluated before `authentication/authentication.go` in the future. Signed-off-by: Simon Pasquier <spasquie@redhat.com>
1 parent 0689ccb commit 9df2d7f

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

authentication/authentication.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ var providerFactories map[string]ProviderFactory
1919
// providersMtx is used to protect the providerFactories.
2020
var providersMtx sync.RWMutex
2121

22-
func init() {
23-
providerFactories = make(map[string]ProviderFactory)
24-
}
25-
2622
// onboardNewProvider is used by the providers to register themselves.
2723
func onboardNewProvider(providerType string, factory ProviderFactory) {
2824
providersMtx.Lock()
2925
defer providersMtx.Unlock()
26+
if providerFactories == nil {
27+
providerFactories = map[string]ProviderFactory{}
28+
}
3029

3130
providerFactories[providerType] = factory
3231
}

0 commit comments

Comments
 (0)