1 package ldcomponents 2 3 import ( 4 "github.com/launchdarkly/go-sdk-common/v3/ldvalue" 5 "github.com/launchdarkly/go-server-sdk/v6/interfaces" 6 "github.com/launchdarkly/go-server-sdk/v6/internal/datasource" 7 "github.com/launchdarkly/go-server-sdk/v6/subsystems" 8 ) 9 10 type nullDataSourceFactory struct{} 11 12 // ExternalUpdatesOnly returns a configuration object that disables a direct connection with LaunchDarkly 13 // for feature flag updates. 14 // 15 // Storing this in the DataSource field of [github.com/launchdarkly/go-server-sdk/v6.Config] causes the 16 // SDK not to retrieve feature flag data from LaunchDarkly, regardless of any other configuration. This is 17 // normally done if you are using the Relay Proxy (https://docs.launchdarkly.com/home/relay-proxy) in 18 // "daemon mode", where an external process-- the Relay Proxy-- connects to LaunchDarkly and populates a 19 // persistent data store with the feature flag data. The data store could also be populated by another 20 // process that is running the LaunchDarkly SDK. If there is no external process updating the data store, 21 // then the SDK will not have any feature flag data and will return application default values only. 22 // 23 // config := ld.Config{ 24 // DataSource: ldcomponents.ExternalUpdatesOnly(), 25 // } 26 func ExternalUpdatesOnly() subsystems.ComponentConfigurer[subsystems.DataSource] { 27 return nullDataSourceFactory{} 28 } 29 30 // DataSourceFactory implementation 31 func (f nullDataSourceFactory) Build( 32 context subsystems.ClientContext, 33 ) (subsystems.DataSource, error) { 34 context.GetLogging().Loggers.Info("LaunchDarkly client will not connect to Launchdarkly for feature flag data") 35 if context.GetDataSourceUpdateSink() != nil { 36 context.GetDataSourceUpdateSink().UpdateStatus(interfaces.DataSourceStateValid, interfaces.DataSourceErrorInfo{}) 37 } 38 return datasource.NewNullDataSource(), nil 39 } 40 41 // DiagnosticDescription implementation 42 func (f nullDataSourceFactory) DescribeConfiguration(context subsystems.ClientContext) ldvalue.Value { 43 // This information is only used for diagnostic events, and if we're able to send diagnostic events, 44 // then by definition we're not completely offline so we must be using daemon mode. 45 return ldvalue.ObjectBuild(). 46 SetBool("usingRelayDaemon", true). 47 Build() 48 } 49