github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/config/remoteconfig/global.go (about)

     1  // TODO: Inject to a global interface e.g. command factory as soon as it exists
     2  // and remove this file.
     3  package remoteconfig
     4  
     5  import (
     6  	"github.com/ddev/ddev/pkg/config/remoteconfig/types"
     7  	statetypes "github.com/ddev/ddev/pkg/config/state/types"
     8  )
     9  
    10  var (
    11  	globalRemoteConfig types.RemoteConfig
    12  )
    13  
    14  // InitGlobal initializes the global remote config. This is done once,
    15  // subsequent calls do not have any effect.
    16  func InitGlobal(config Config, stateManager statetypes.State, isInternetActive func() bool) types.RemoteConfig {
    17  	if globalRemoteConfig == nil {
    18  		globalRemoteConfig = New(&config, stateManager, isInternetActive)
    19  	}
    20  
    21  	return globalRemoteConfig
    22  }
    23  
    24  // GetGlobal returns the global remote config. InitGlobal must be
    25  // called in advance or the function will panic.
    26  func GetGlobal() types.RemoteConfig {
    27  	if globalRemoteConfig == nil {
    28  		panic("error remoteconfig.InitGlobal was not called before accessing remote config")
    29  	}
    30  
    31  	return globalRemoteConfig
    32  }