Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Aug 29, 2024
1 parent bc81990 commit 26e8b82
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
17 changes: 17 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,22 @@ type Config struct {
// requests to LaunchDarkly's global CDN (Secondary Synchronizer)
// 5. After a period of time, the SDK will swap back to the realtime Flag Delivery Network if it becomes
// available again.
//
// The default streaming mode configuration is preferred for most use-cases (DataSystem().StreamingPreferred()).
// Sometimes streaming connections are blocked by firewalls or proxies. If this is the case, a polling-only mode
// can be configured:
//
// config := ld.Config{
// DataSystem: ldcomponents.DataSystem().PollingOnly(),
// }
//
// If you'd like to load data from a local source to provide redundancy if there is a problem
// connecting to LaunchDarkly, you can add a custom initializer:
//
// config := ld.Config {
// DataSystem: ldcomponents.DataSystem().PrependInitializers(myCustomInitializer),
// }
//
// The initializer(s) will run before LaunchDarkly's default initializer.
DataSystem subsystems.ComponentConfigurer[subsystems.DataSystemConfiguration]
}
29 changes: 19 additions & 10 deletions ldcomponents/data_system_configuration_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ type DataSystemConfigurationBuilder struct {
}

func DataSystem() *DataSystemConfigurationBuilder {
return &DataSystemConfigurationBuilder{
primarySyncBuilder: ldcomponents.StreamingDataSource(),
secondarySyncBuilder: ldcomponents.PollingDataSource(),
storeBuilder: nil, // in-memory only
initializerBuilders: []subsystems.ComponentConfigurer[subsystems.Initializer]{ldcomponents.PollingInitializer()},
}
d := &DataSystemConfigurationBuilder{}
return d.StreamingPreferred()
}

func (d *DataSystemConfigurationBuilder) Store(store subsystems.ComponentConfigurer[subsystems.DataStore]) *DataSystemConfigurationBuilder {
Expand All @@ -34,16 +30,29 @@ func (d *DataSystemConfigurationBuilder) Initializers(initializers ...subsystems
return d
}

func (d *DataSystemConfigurationBuilder) PrimarySynchronizer(sync subsystems.ComponentConfigurer[subsystems.Synchronizer]) *DataSystemConfigurationBuilder {
d.primarySyncBuilder = sync
func (d *DataSystemConfigurationBuilder) PrependInitializers(initializers ...subsystems.ComponentConfigurer[subsystems.Initializer]) *DataSystemConfigurationBuilder {
d.initializerBuilders = append(initializers, d.initializerBuilders...)
return d
}

func (d *DataSystemConfigurationBuilder) SecondarySynchronizer(sync subsystems.ComponentConfigurer[subsystems.Synchronizer]) *DataSystemConfigurationBuilder {
d.secondarySyncBuilder = sync
func (d *DataSystemConfigurationBuilder) Synchronizers(primary, secondary subsystems.ComponentConfigurer[subsystems.Synchronizer]) *DataSystemConfigurationBuilder {
d.primarySyncBuilder = primary
d.secondarySyncBuilder = secondary
return d
}

func (d *DataSystemConfigurationBuilder) PollingOnly() *DataSystemConfigurationBuilder {
return d.Synchronizer(ldcomponents.PollingDataSource())
}

func (d *DataSystemConfigurationBuilder) StreamingPreferred() *DataSystemConfigurationBuilder {
return d.Initializers(ldcomponents.PollingInitializer()).Synchronizer(ldcomponents.StreamingDataSource(), ldcomponents.PollingDataSource())
}

func (d *DataSystemConfigurationBuilder) Synchronizer(sync subsystems.ComponentConfigurer[subsystems.Synchronizer]) *DataSystemConfigurationBuilder {
return d.Synchronizers(sync, nil)
}

func (d *DataSystemConfigurationBuilder) Build(
context subsystems.ClientContext,
) (subsystems.DataSystemConfiguration, error) {
Expand Down
14 changes: 0 additions & 14 deletions subsystems/datasystem_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,3 @@ type DataSystemConfiguration struct {
Initializers []Initializer
Synchronizers SynchronizersConfiguration
}

/**
DataSystemConfiguration {
Store: ldcomponents.Empty(), || ldcomponents.PersistentStore(
Initializers: []ldcomponents.Initializer{
ldcomponents.PollFDv2()
},
Synchronizers: ldcomponents.SynchronizersConfiguration{
Primary: ldcomponents.StreamingFDv2(),
Secondary: ldcomponents.PollFDv2()
}
}
*/

0 comments on commit 26e8b82

Please sign in to comment.