...

Source file src/github.com/launchdarkly/go-server-sdk/v6/config.go

Documentation: github.com/launchdarkly/go-server-sdk/v6

     1  package ldclient
     2  
     3  import (
     4  	ldevents "github.com/launchdarkly/go-sdk-events/v2"
     5  	"github.com/launchdarkly/go-server-sdk/v6/interfaces"
     6  	"github.com/launchdarkly/go-server-sdk/v6/subsystems"
     7  )
     8  
     9  // Config exposes advanced configuration options for [LDClient].
    10  //
    11  // All of these settings are optional, so an empty Config struct is always valid. See the description of each
    12  // field for the default behavior if it is not set.
    13  //
    14  // Some of the Config fields are simple types, but others contain configuration builders for subcomponents of
    15  // the SDK. When these are represented by the ComponentConfigurer interface, the actual implementation types
    16  // are provided by corresponding functions in the [ldcomponents] package. For instance, to set the Events
    17  // field to a configuration in which the SDK will flush analytics events every 10 seconds:
    18  //
    19  //	var config ld.Config
    20  //	config.Events = ldcomponents.Events().FlushInterval(time.Second * 10)
    21  //
    22  // The interfaces are defined separately from the built-in component implementations because you could also
    23  // define your own implementation, for custom SDK integrations.
    24  type Config struct {
    25  	// Provides configuration of the SDK's Big Segments feature.
    26  	//
    27  	// "Big Segments" are a specific type of user segments. For more information, read the LaunchDarkly
    28  	// documentation about user segments: https://docs.launchdarkly.com/home/users
    29  	//
    30  	// To enable Big Segments, set this field to the configuration builder that is returned by
    31  	// ldcomponents.BigSegments(), which allows you to specify what database to use as well as other
    32  	// options.
    33  	//
    34  	// If nil, there is no implementation and Big Segments cannot be evaluated. In this case, any flag
    35  	// evaluation that references a Big Segment will behave as if no users are included in any Big
    36  	// Segments, and the EvaluationReason associated with any such flag evaluation will return
    37  	// ldreason.BigSegmentsStoreNotConfigured from its GetBigSegmentsStatus() method.
    38  	//
    39  	//     // example: use Redis, with default properties
    40  	//     import ldredis "github.com/launchdarkly/go-server-sdk-redis-redigo"
    41  	//
    42  	//     config.BigSegmentStore = ldcomponents.BigSegments(ldredis.BigSegmentStore())
    43  	BigSegments subsystems.ComponentConfigurer[subsystems.BigSegmentsConfiguration]
    44  
    45  	// Sets the implementation of DataSource for receiving feature flag updates.
    46  	//
    47  	// If Offline is set to true, then DataSource is ignored.
    48  	//
    49  	// The interface type for this field allows you to set it to any of the following:
    50  	//   - ldcomponents.StreamingDataSource(), which enables streaming data and provides a builder to further
    51  	//     configure streaming behavior.
    52  	//   - ldcomponents.PollingDataSource(), which turns off streaming, enables polling, and provides a builder
    53  	//     to further configure polling behavior.
    54  	//   - ldcomponents.ExternalUpdatesOnly(), which turns off all data sources unless an external process is
    55  	//     providing data via a database.
    56  	//   - ldfiledata.DataSource() or ldtestdata.DataSource(), which provide configurable local data sources
    57  	//     for testing.
    58  	//   - Or, a custom component that implements ComponentConfigurer[DataSource].
    59  	//
    60  	//     // example: using streaming mode and setting streaming options
    61  	//     config.DataSource = ldcomponents.StreamingDataSource().InitialReconnectDelay(time.Second)
    62  	//
    63  	//     // example: using polling mode and setting polling options
    64  	//     config.DataSource = ldcomponents.PollingDataSource().PollInterval(time.Minute)
    65  	//
    66  	//     // example: specifying that data will be updated by an external process (such as the Relay Proxy)
    67  	//     config.DataSource = ldcomponents.ExternalUpdatesOnly()
    68  	DataSource subsystems.ComponentConfigurer[subsystems.DataSource]
    69  
    70  	// Sets the implementation of DataStore for holding feature flags and related data received from
    71  	// LaunchDarkly.
    72  	//
    73  	// If nil, the default is ldcomponents.InMemoryDataStore().
    74  	//
    75  	// The other option is to use a persistent data store-- that is, a database integration. These all use
    76  	// ldcomponents.PersistentDataStore(), plus an adapter for the specific database. LaunchDarkly provides
    77  	// adapters for several databases, as described in the Reference Guide:
    78  	// https://docs.launchdarkly.com/sdk/concepts/data-stores
    79  	//
    80  	// You could also define your own database integration by implementing the PersistentDataStore interface.
    81  	//
    82  	//     // example: use Redis, with default properties
    83  	//     import ldredis "github.com/launchdarkly/go-server-sdk-redis-redigo"
    84  	//
    85  	//     config.DataStore = ldcomponents.PersistentDataStore(ldredis.DataStore())
    86  	DataStore subsystems.ComponentConfigurer[subsystems.DataStore]
    87  
    88  	// Set to true to opt out of sending diagnostic events.
    89  	//
    90  	// Unless DiagnosticOptOut is set to true, the client will send some diagnostics data to the LaunchDarkly
    91  	// servers in order to assist in the development of future SDK improvements. These diagnostics consist of an
    92  	// initial payload containing some details of the SDK in use, the SDK's configuration, and the platform the
    93  	// SDK is being run on, as well as payloads sent periodically with information on irregular occurrences such
    94  	// as dropped events.
    95  	DiagnosticOptOut bool
    96  
    97  	// Sets the SDK's behavior regarding analytics events.
    98  	//
    99  	// The interface type for this field allows you to set it to either:
   100  	//   - ldcomponents.SendEvents(), a configuration builder that allows you to customize event behavior;
   101  	//   - ldcomponents.NoEvents(), which turns off event delivery.
   102  	//
   103  	// If this field is unset/nil, the default is ldcomponents.SendEvents() with no custom options.
   104  	//
   105  	// If Offline is set to true, then event delivery is always off and Events is ignored.
   106  	//
   107  	//     // example: enable events, flush the events every 10 seconds, buffering up to 5000 events
   108  	//     config.Events = ldcomponents.SendEvents().FlushInterval(10 * time.Second).Capacity(5000)
   109  	Events subsystems.ComponentConfigurer[ldevents.EventProcessor]
   110  
   111  	// Provides configuration of the SDK's network connection behavior.
   112  	//
   113  	// The interface type used here is implemented by ldcomponents.HTTPConfigurationBuilder, which
   114  	// you can create by calling ldcomponents.HTTPConfiguration(). See that method for an explanation
   115  	// of how to configure the builder. If nil, the default is ldcomponents.HTTPConfiguration() with
   116  	// no custom settings.
   117  	//
   118  	// If Offline is set to true, then HTTP is ignored.
   119  	//
   120  	//     // example: set connection timeout to 8 seconds and use a proxy server
   121  	//     config.HTTP = ldcomponents.HTTPConfiguration().ConnectTimeout(8 * time.Second).ProxyURL(myProxyURL)
   122  	HTTP subsystems.ComponentConfigurer[subsystems.HTTPConfiguration]
   123  
   124  	// Provides configuration of the SDK's logging behavior.
   125  	//
   126  	// The interface type used here is implemented by ldcomponents.LoggingConfigurationBuilder, which
   127  	// you can create by calling ldcomponents.Logging(). See that method for an explanation of how to
   128  	// configure the builder. If nil, the default is ldcomponents.Logging() with no custom settings.
   129  	// You can also set this field to ldcomponents.NoLogging() to disable all logging.
   130  	//
   131  	// This example sets the minimum logging level to Warn, so Debug and Info messages will not be logged:
   132  	//
   133  	//     // example: enable logging only for Warn level and above
   134  	//     // (note: ldlog is github.com/launchdarkly/go-sdk-common/v3/ldlog)
   135  	//     config.Logging = ldcomponents.Logging().MinLevel(ldlog.Warn)
   136  	Logging subsystems.ComponentConfigurer[subsystems.LoggingConfiguration]
   137  
   138  	// Sets whether this client is offline. An offline client will not make any network connections to LaunchDarkly,
   139  	// and will return default values for all feature flags.
   140  	//
   141  	// For more information, see the Reference Guide: https://docs.launchdarkly.com/sdk/features/offline-mode#go
   142  	Offline bool
   143  
   144  	// Provides configuration of custom service base URIs.
   145  	//
   146  	// Set this field only if you want to specify non-default values for any of the URIs. You may set
   147  	// individual values such as Streaming, or use the helper method ldcomponents.RelayProxyEndpoints().
   148  	//
   149  	// The default behavior, if you do not set any of these values, is that the SDK will connect to
   150  	// the standard endpoints in the LaunchDarkly production service. There are several use cases for
   151  	// changing these values:
   152  	//
   153  	// - You are using the LaunchDarkly Relay Proxy (https://docs.launchdarkly.com/home/advanced/relay-proxy).
   154  	// In this case, call ldcomponents.RelayProxyEndpoints and put its return value into
   155  	// Config.ServiceEndpoints. Note that this is not the same as a regular HTTP proxy, which would
   156  	// be set with ldcomponents.HTTPConfiguration().
   157  	//
   158  	//     config := ld.Config{
   159  	//         ServiceEndpoints: ldcomponents.RelayProxyEndpoints("http://my-relay-host:8080"),
   160  	//     }
   161  	//
   162  	//     // Or, if you want analytics events to be delivered directly to LaunchDarkly rather
   163  	//     // than having them forwarded through the Relay Proxy:
   164  	//     config := ld.Config{
   165  	//         ServiceEndpoints: ldcomponents.RelayProxyEndpoints("http://my-relay-host:8080").
   166  	//             WithoutEventForwarding(),
   167  	//     }
   168  	//
   169  	// - You are connecting to a private instance of LaunchDarkly, rather than the standard production
   170  	// services. In this case, there will be custom base URIs for each service, so you must set
   171  	// Streaming, Polling, and Events to whatever URIs that have been defined for your instance.
   172  	//
   173  	//     config := ld.Config{
   174  	//         ServiceEndpoints: interfaces.ServiceEndpoints{
   175  	//             Streaming: "https://some-subdomain-a.launchdarkly.com",
   176  	//             Polling: "https://some-subdomain-b.launchdarkly.com",
   177  	//             Events: "https://some-subdomain-c.launchdarkly.com",
   178  	//         },
   179  	//     }
   180  	//
   181  	// - You are connecting to a test fixture that simulates the service endpoints. In this case, you
   182  	// may set the base URIs to whatever you want, although the SDK will still set the URI paths to
   183  	// the expected paths for LaunchDarkly services.
   184  	ServiceEndpoints interfaces.ServiceEndpoints
   185  
   186  	// Provides configuration of application metadata. See interfaces.ApplicationInfo.
   187  	//
   188  	// Application metadata may be used in LaunchDarkly analytics or other product features, but does not
   189  	// affect feature flag evaluations.
   190  	ApplicationInfo interfaces.ApplicationInfo
   191  }
   192  

View as plain text