This is a major rewrite that introduces a cleaner API design, adds new features, and makes the SDK code easier to maintain and extend. See the Go 4.x to 5.0 migration guide for an in-depth look at the changes in this version; the following is a summary.
LDClient.GetFlagTracker().LDClient.GetDataSourceStatusProvider(). This allows you to check the current connection status, and to be notified if this status changes.LDClient.GetDataStoreStatusProvider(). This allows you to check whether database updates are succeeding, to be notified if this status changes, and to get caching statistics.LDClient.WithEventsDisabled() is a decorator that allows you to temporarily turn off analytics events even if events are enabled in your configuration.LDConfig.Logging is a new configuration category for options related to logging. See ldcomponents.Logging() and ldcomponents.NoLogging().testhelpers/ldtestdata package provides an alternative to ldfiledata for simulating feature flag data in test code.AllFlagsState() can now be constructed (such as for testing purposes) with flagstate.NewAllFlagsBuilder().interfaces, LDClientInterface, LDClientEvaluations, and LDClientEvents are new interfaces describing the existing methods of LDClient. These may be useful for creating mocks in testing.User and UserBuilder types are now in the package gopkg.in/launchdarkly/go-sdk-common.v2/lduser. Users can no longer be created as inline structs; you must use lduser.NewUser, lduser.NewAnonymousUser, or lduser.NewUserBuilder.EvaluationDetail and EvaluationReason types are now in the package gopkg.in/launchdarkly/go-sdk-common.v2/ldreason.EvaluationDetail.VariationIndex now uses the type ldvalue.OptionalInt instead of the *int pointer type.EvaluationReason is now a struct rather than an interface, and is just one type rather than having separate types for each Kind.ldlog.Loggers abstraction is now in the package gopkg.in/launchdarkly/go-sdk-common.v2/ldlog.Config, but as builder methods on a component that is provided by the new ldcomponents package and is then placed in Config. For instance, instead of setting Capacity: 1000, you would now set Events: ldcomponents.SendEvents().Capacity(1000); to disable events, instead of setting SendEvents: false, you would set Events: ldcomponents.NoEvents() (note that NoEvents does not allow you to set Capacity, since that would be meaningless if events are disabled). Similarly, to disable streaming and use polling, set DataSource: ldcomponents.PollingDataSource() which then provides optional methods for configuring polling. See Config and ldcomponents for more details.redis, lddynamodb, and ldconsul subpackages have been moved to their own repositories: go-server-sdk-redis-redigo, go-server-sdk-dynamodb, and go-server-sdk-consul. This removes the transitive dependencies on Redigo, AWS, etc.— which would otherwise be loaded for all Go modules that reference the SDK, even if you do not reference the subpackages that use them— and also allows fixes or new features to be released for those integrations without requiring a new SDK release.ldcomponents.PersistentDataStore. See the new repositories for documentation and examples.ldfiledata integration now also uses a builder pattern for configuration.LDClient.AllFlagsState() are now in the interfaces/flagstate package, and their names have changed as follows: FeatureFlagsState is now flagstate.AllFlags; ClientSideOnly is now flagstate.OptionClientSideOnly(); DetailsOnlyForTrackedFlags is now flagstate.OptionDetailsOnlyForTrackedFlags()`.FeatureStore and UpdateProcessor have been renamed to DataStore and DataSource. The factory interfaces for these components now receive SDK configuration options in a different way that does not expose other components' configurations to each other.PersistentDataStore interface for creating your own database integrations has been simplified by moving all of the serialization and caching logic into the main SDK code.FeatureFlag, Segment, and other data model types are now in the package gopkg.in/launchdarkly/go-server-sdk-evaluation.v1. Application code will not normally need to refer to these types.gopkg.in/launchdarkly/go-sdk-events.v1. Application code will not normally need to refer to these types.ERROR level in most cases but sometimes at WARN level. They are now all at WARN level, but with a new behavior: if connection failures continue without a successful retry for a certain amount of time, the SDK will log a special ERROR-level message to warn you that this is not just a brief outage. The amount of time is one minute by default, but can be changed with the new LogDataSourceOutageAsErrorAfter option in LoggingConfigurationBuilder.User from JSON with json.Unmarshal now returns an error if the key property is missing or null.DefaultConfig was removed since it is no longer necessary: an empty Config{} is valid and will provide all of the documented default behavior. If you need to access the default value for a property, use the corresponding constant, such as ldcomponents.DefaultEventsCapacity.sharedtest subpackage, which contains test helpers for the SDK itself, is now internal and cannot be used from application code. Test helpers that were meant to be public are now in the testhelpers subpackage.sharedtest/ldtestdata package provides an alternative to ldfiledata for simulating feature flag data in test code.EvaluationDetail type from go-sdk-common now uses a new type, ldvalue.OptionalInt, for the VariationIndex field. Previously, this field was an int and used the special value -1 to represent "undefined". OptionalInt has a clearer way of indicating when the value is undefined.A version was skipped because the 5.0.0-beta.4 tag had been applied to the wrong commit.
LDClient.WithEventsDisabled() is a decorator that allows you to temporarily turn off analytics events even if events are enabled in your configuration.AllFlagsState() can now be constructed (such as for testing purposes) with flagstate.NewAllFlagsBuilder().interfaces, LDClientInterface, LDClientEvaluations, and LDClientEvents are new interfaces describing the existing methods of LDClient. These may be useful for creating mocks in testing.LDClient.AllFlagsState() are now in the interfaces/flagstate package, and their names have changed as follows: FeatureFlagsState is now flagstate.AllFlags; ClientSideOnly is now flagstate.OptionClientSideOnly(); DetailsOnlyForTrackedFlags is now flagstate.OptionDetailsOnlyForTrackedFlags()`.clientSideAvailability property which may be sent by LaunchDarkly services as an alternate way of indicating whether a flag is enabled for use by client-side JavaScript SDKs. This change does not introduce any new SDK functionality.This beta release is being made available for testing and user feedback, due to the large number of changes from Go SDK 4.x. Features are still subject to change in the final 5.0.0 release. API documentation for this version is at https://pkg.go.dev/gopkg.in/launchdarkly/go-server-sdk.v5@v5.0.0-beta.3 and https://pkg.go.dev/gopkg.in/launchdarkly/go-sdk-common.v2@v2.0.0-beta.3.
Changes from the previous beta release:
ldredis, lddynamodb, and ldconsul packages are no longer in this repository. They have been moved to separate projects: http://github.com/launchdarkly/go-server-sdk-redis, http://github.com/launchdarkly/go-server-sdk-dynamodb, http://github.com/launchdarkly/go-server-sdk-consul. This removes the transitive dependencies on Redigo, AWS, etc.--which would otherwise be loaded for all Go modules that reference the SDK, even if you do not reference the subpackages that use them-- and also allows fixes or new features to be released for those integrations without requiring a new SDK release.This beta release is being made available for testing and user feedback, due to the large number of changes from Go SDK 4.x. Features are still subject to change in the final 5.0.0 release. API documentation for this version is at https://pkg.go.dev/gopkg.in/launchdarkly/go-server-sdk.v5@v5.0.0-beta.2 and https://pkg.go.dev/gopkg.in/launchdarkly/go-sdk-common.v2@v2.0.0-beta.2.
This is a major rewrite that introduces a cleaner API design, adds new features, and makes the SDK code easier to maintain and extend. See the Go 4.x to 5.0 migration guide for an in-depth look at the changes in this version; the following is a summary.
LDClient.GetFlagTracker().LDClient.GetDataSourceStatusProvider(). This allows you to check the current connection status, and to be notified if this status changes.LDClient.GetDataStoreStatusProvider(). This allows you to check whether database updates are succeeding, to be notified if this status changes, and to get caching statistics.LDConfig.Logging is a new configuration category for options related to logging. See ldcomponents.Logging().User and UserBuilder types are now in the package gopkg.in/launchdarkly/go-sdk-common.v2/lduser. Users can no longer be created as inline structs; you must use lduser.NewUser, lduser.NewAnonymousUser, or lduser.NewUserBuilder.EvaluationDetail and EvaluationReason types are now in the package gopkg.in/launchdarkly/go-sdk-common.v2/ldreason.EvaluationReason is now a struct rather than an interface, and is just one type rather than having separate types for each Kind.ldlog.Loggers abstraction is now in the package gopkg.in/launchdarkly/go-sdk-common.v2/ldlog.Config, but as builder methods on a component that is provided by the new ldcomponents package and is then placed in Config. For instance, instead of setting Capacity: 1000, you would now set Events: ldcomponents.SendEvents().Capacity(1000); to disable events, instead of setting SendEvents: false, you would set Events: ldcomponents.NoEvents() (note that NoEvents does not allow you to set Capacity, since that would be meaningless if events are disabled). Similarly, to disable streaming and use polling, set DataSource: ldcomponents.PollingDataSource() which then provides optional methods for configuring polling. See Config and ldcomponents for more details.redis package has been renamed to ldredis.ldconsul, lddynamodb, ldredis, and ldfiledata now use a builder pattern (like the rest of the SDK component configurations) instead of a factory function with option arguments. For instance, you would write ldredis.DataSource().URL("redis://host").Prefix("prefix") instead of redis.NewRedisDataStoreFactory(redis.URL("redis://host"), redis.Prefix("prefix")).FeatureStore and UpdateProcessor have been renamed to DataStore and DataSource. The factory interfaces for these components now receive SDK configuration options in a different way that does not expose other components' configurations to each other.PersistentDataStore interface for creating your own database integrations has been simplified by moving all of the serialization and caching logic into the main SDK code.FeatureFlag, Segment, and other data model types are now in the package gopkg.in/launchdarkly/go-server-sdk-evaluation.v1. Application code will not normally need to refer to these types.gopkg.in/launchdarkly/go-sdk-events.v1. Application code will not normally need to refer to these types.dep or govendor, you will still be able to import the SDK the same as before; however, be aware that it now has several dependent repositories (all under gopkg.in/launchdarkly), so whenever you update to a newer version of the SDK you may need to update those as well—the SDK cannot specify its own preferred dependency versions unless you use modules.ERROR level in most cases but sometimes at WARN level. They are now all at WARN level, but with a new behavior: if connection failures continue without a successful retry for a certain amount of time, the SDK will log a special ERROR-level message to warn you that this is not just a brief outage. The amount of time is one minute by default, but can be changed with the new LogDataSourceOutageAsErrorAfter option in LoggingConfigurationBuilder.DefaultConfig was removed since it is no longer necessary: an empty Config{} is valid and will provide all of the documented default behavior. If you need to access the default value for a property, use the corresponding constant, such as ldcomponents.DefaultEventsCapacity.sharedtest subpackage, which contains test helpers for the SDK itself, is now internal and cannot be used from application code. Test helpers that were meant to be public are now in the testhelpers subpackage.Please use v5.0.0-beta.2 instead. The beta.1 release was created with an incorrect Git tag, which cannot be corrected due to Go module proxy caching. The beta.2 release is identical except for the version string and the tag.
We are pushing some updates to the public repositories before the beta release is ready, in order to be able to test code that can only be built against public repos and not the development repos. This tag will be removed after the GA release.
go-yaml that is optionally used by the file data source feature, to version 2.3.0, due to a vulnerability warning on version 2.2.1. Note that this is just the dependency version used when building the SDK; an application that uses the SDK may get different versions of its transitive dependencies depending on the package management system being used. The vulnerability would not affect normal usage of the SDK without the file data source, or with YAML files in the SDK's correct documented format.Config field StreamInitialReconnectDelay specifies how long the SDK should initially wait before retrying the stream connection after a failure. The default is one second; previously it was three seconds.go-server-sdk instead of Go.This release introduces new types for building user properties and representing arbitrary JSON values. In the next major version, these will entirely replace the current deprecated equivalents.
NewUserBuilder, and its associated interfaces UserBuilder and UserBuilderCanMakeAttributePrivate. This is the new preferred mechanism for creating User instances when you need to set multiple properties; it reduces unsafe and inconvenient use of pointers.User property getter methods such as GetName().gopkg.in/launchdarkly/go-sdk-common.v1, which provides the helper types ldvalue.Value and ldvalue.OptionalString.LDClient, JSONVariation and JSONVariationDetail are the new preferred mechanism for evaluating flags whose values can be of any JSON type. The value is represented as an ldvalue.Value rather than a json.RawMessage, but can be easily converted to json.RawMessage or to other Go types.LDClient, TrackData and TrackMetric are the new preferred versions of Track and TrackWithMetric; they use ldvalue.Value rather than interface{} for the data parameter.EvaluationReason methods GetRuleIndex(), GetRuleID(), GetPrerequisiteKey(), GetErrorKind(). These were formerly only on concrete implementation types such as EvaluationReasonRuleMatch; they are being added to the interface type because in a future version, it will be changed to a struct.os.Stderr with a minimum level of ldlog.Info, omitting only Debug-level messages. A bug introduced in 4.12.0 caused the default logger not to produce any output. It will now log at Info level by default again, as documented.User. In a future version, these will be hidden. Use getters such as GetName() to read these fields, and NewUserBuilder to set them.LDClient, JsonVariation, JsonVariationDetail, Track, and TrackWithMetric. Use JSONVariation, JSONVariationDetail, TrackData, TrackEvent, or TrackMetric instead.EvaluationReason implementation types such as EvaluationReasonRuleMatch are deprecated. Instead of casting to these types, use EvaluationReason methods such as GetKind() and GetErrorKind().Note: if you are using the LaunchDarkly Relay Proxy to forward events, update the Relay to version 5.10.0 or later before updating to this Go SDK version.
Config.DiagnosticOptOut or configured with Config.DiagnosticRecordingInterval.Config fields WrapperName and WrapperVersion allow a library that uses the Go SDK to identify itself for usage data if desired.ldhttp.ProxyOption, for specifying an HTTP/HTTPS proxy URL programmatically rather than using environment variables.NewHTTPClientFactory did not work correctly: it did construct an HTTP client, but did not actually apply any ldhttp transport options that were specified.FeatureFlag, Segment, etc. are all deprecated and will be moved to another package in the future. Application code should never need to reference these types, and feature store integration code should only use abstractions like ld.VersionedData.SegmentExplanation, HttpStatusError, ParseTime, ParseFloat64, and ToJsonRawMessage were meant for internal use, and will be removed or made private in a future version.