...

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

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

     1  package subsystems
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/launchdarkly/go-server-sdk/v6/interfaces"
     7  )
     8  
     9  // ClientContext provides context information from LDClient when creating other components.
    10  //
    11  // This is passed as a parameter to the factory methods for implementations of DataStore, DataSource,
    12  // etc. The actual implementation type may contain other properties that are only relevant to the built-in
    13  // SDK components and are therefore not part of the public interface; this allows the SDK to add its own
    14  // context information as needed without disturbing the public API. However, for test purposes you may use
    15  // the simple struct type BasicClientContext.
    16  type ClientContext interface {
    17  	// GetSDKKey returns the configured SDK key.
    18  	GetSDKKey() string
    19  
    20  	// GetApplicationInfo returns the configuration for application metadata.
    21  	GetApplicationInfo() interfaces.ApplicationInfo
    22  
    23  	// GetHTTP returns the configured HTTPConfiguration.
    24  	GetHTTP() HTTPConfiguration
    25  
    26  	// GetLogging returns the configured LoggingConfiguration.
    27  	GetLogging() LoggingConfiguration
    28  
    29  	// GetOffline returns true if the client was configured to be completely offline.
    30  	GetOffline() bool
    31  
    32  	// GetServiceEndpoints returns the configuration for service URIs.
    33  	GetServiceEndpoints() interfaces.ServiceEndpoints
    34  
    35  	// GetDataSourceUpdateSink returns the component that DataSource implementations use to deliver
    36  	// data and status updates to the SDK.
    37  	//
    38  	// This component is only available when the SDK is creating a DataSource. Otherwise the method
    39  	// returns nil.
    40  	GetDataSourceUpdateSink() DataSourceUpdateSink
    41  
    42  	// GetDataStoreUpdateSink returns the component that DataSource implementations use to deliver
    43  	// data store status updates to the SDK.
    44  	//
    45  	// This component is only available when the SDK is creating a DataStore. Otherwise the method
    46  	// returns nil.
    47  	GetDataStoreUpdateSink() DataStoreUpdateSink
    48  }
    49  
    50  // BasicClientContext is the basic implementation of the ClientContext interface, not including any
    51  // private fields that the SDK may use for implementation details.
    52  type BasicClientContext struct {
    53  	SDKKey               string
    54  	ApplicationInfo      interfaces.ApplicationInfo
    55  	HTTP                 HTTPConfiguration
    56  	Logging              LoggingConfiguration
    57  	Offline              bool
    58  	ServiceEndpoints     interfaces.ServiceEndpoints
    59  	DataSourceUpdateSink DataSourceUpdateSink
    60  	DataStoreUpdateSink  DataStoreUpdateSink
    61  }
    62  
    63  func (b BasicClientContext) GetSDKKey() string { return b.SDKKey } //nolint:revive
    64  
    65  func (b BasicClientContext) GetApplicationInfo() interfaces.ApplicationInfo { return b.ApplicationInfo } //nolint:revive
    66  
    67  func (b BasicClientContext) GetHTTP() HTTPConfiguration { //nolint:revive
    68  	ret := b.HTTP
    69  	if ret.CreateHTTPClient == nil {
    70  		ret.CreateHTTPClient = func() *http.Client {
    71  			client := *http.DefaultClient
    72  			return &client
    73  		}
    74  	}
    75  	return ret
    76  }
    77  
    78  func (b BasicClientContext) GetLogging() LoggingConfiguration { return b.Logging } //nolint:revive
    79  
    80  func (b BasicClientContext) GetOffline() bool { return b.Offline } //nolint:revive
    81  
    82  func (b BasicClientContext) GetServiceEndpoints() interfaces.ServiceEndpoints { //nolint:revive
    83  	return b.ServiceEndpoints
    84  }
    85  
    86  func (b BasicClientContext) GetDataSourceUpdateSink() DataSourceUpdateSink { //nolint:revive
    87  	return b.DataSourceUpdateSink
    88  }
    89  
    90  func (b BasicClientContext) GetDataStoreUpdateSink() DataStoreUpdateSink { //nolint:revive
    91  	return b.DataStoreUpdateSink
    92  }
    93  

View as plain text