From c6e1c44ea3d2bb47610b2faeebad58d7fa4aae5e Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Thu, 15 Jan 2026 10:20:12 +0100 Subject: [PATCH] chore: simplify init functions 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 --- authentication/authentication.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/authentication/authentication.go b/authentication/authentication.go index 5353fa6e1..db6f97a9e 100644 --- a/authentication/authentication.go +++ b/authentication/authentication.go @@ -19,14 +19,13 @@ var providerFactories map[string]ProviderFactory // providersMtx is used to protect the providerFactories. var providersMtx sync.RWMutex -func init() { - providerFactories = make(map[string]ProviderFactory) -} - // onboardNewProvider is used by the providers to register themselves. func onboardNewProvider(providerType string, factory ProviderFactory) { providersMtx.Lock() defer providersMtx.Unlock() + if providerFactories == nil { + providerFactories = map[string]ProviderFactory{} + } providerFactories[providerType] = factory }