Skip to content

Commit 2caaa0d

Browse files
author
Michael Ng
authored
chore(docs): Clean up public doc strings on client, factory and top-level components. (#196)
1 parent 327c59b commit 2caaa0d

File tree

9 files changed

+86
-78
lines changed

9 files changed

+86
-78
lines changed

optimizely.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/optimizely/go-sdk/pkg/entities"
2222
)
2323

24-
// Client returns an OptimizelyClient instantitated with the given key and options
24+
// Client returns an OptimizelyClient instantiated with the given key and options
2525
func Client(sdkKey string, options ...client.OptionFunc) (*client.OptimizelyClient, error) {
2626
factory := &client.OptimizelyFactory{
2727
SDKKey: sdkKey,

pkg/client/client.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ type OptimizelyClient struct {
4242
executionCtx utils.ExecutionCtx
4343
}
4444

45-
// Activate returns the key of the variation the user is bucketed into and sends an impression event to the Optimizely log endpoint
45+
// Activate returns the key of the variation the user is bucketed into and queues up an impression event to be sent to
46+
// the Optimizely log endpoint for results processing.
4647
func (o *OptimizelyClient) Activate(experimentKey string, userContext entities.UserContext) (result string, err error) {
4748

4849
defer func() {
@@ -77,7 +78,8 @@ func (o *OptimizelyClient) Activate(experimentKey string, userContext entities.U
7778
return result, err
7879
}
7980

80-
// IsFeatureEnabled returns true if the feature is enabled for the given user
81+
// IsFeatureEnabled returns true if the feature is enabled for the given user. If the user is part of a feature test
82+
// then an impression event will be queued up to be sent to the Optimizely log endpoint for results processing.
8183
func (o *OptimizelyClient) IsFeatureEnabled(featureKey string, userContext entities.UserContext) (result bool, err error) {
8284

8385
defer func() {
@@ -122,7 +124,8 @@ func (o *OptimizelyClient) IsFeatureEnabled(featureKey string, userContext entit
122124
return result, err
123125
}
124126

125-
// GetEnabledFeatures returns an array containing the keys of all features in the project that are enabled for the given user.
127+
// GetEnabledFeatures returns an array containing the keys of all features in the project that are enabled for the given
128+
// user. For features tests, impression events will be queued up to be sent to the Optimizely log endpoint for results processing.
126129
func (o *OptimizelyClient) GetEnabledFeatures(userContext entities.UserContext) (enabledFeatures []string, err error) {
127130

128131
defer func() {
@@ -156,7 +159,7 @@ func (o *OptimizelyClient) GetEnabledFeatures(userContext entities.UserContext)
156159
return enabledFeatures, err
157160
}
158161

159-
// GetFeatureVariableBoolean returns boolean feature variable value
162+
// GetFeatureVariableBoolean returns the feature variable value of type bool associated with the given feature and variable keys.
160163
func (o *OptimizelyClient) GetFeatureVariableBoolean(featureKey, variableKey string, userContext entities.UserContext) (value bool, err error) {
161164

162165
val, valueType, err := o.GetFeatureVariable(featureKey, variableKey, userContext)
@@ -170,7 +173,7 @@ func (o *OptimizelyClient) GetFeatureVariableBoolean(featureKey, variableKey str
170173
return convertedValue, err
171174
}
172175

173-
// GetFeatureVariableDouble returns double feature variable value
176+
// GetFeatureVariableDouble returns the feature variable value of type double associated with the given feature and variable keys.
174177
func (o *OptimizelyClient) GetFeatureVariableDouble(featureKey, variableKey string, userContext entities.UserContext) (value float64, err error) {
175178

176179
val, valueType, err := o.GetFeatureVariable(featureKey, variableKey, userContext)
@@ -184,7 +187,7 @@ func (o *OptimizelyClient) GetFeatureVariableDouble(featureKey, variableKey stri
184187
return convertedValue, err
185188
}
186189

187-
// GetFeatureVariableInteger returns integer feature variable value
190+
// GetFeatureVariableInteger returns the feature variable value of type int associated with the given feature and variable keys.
188191
func (o *OptimizelyClient) GetFeatureVariableInteger(featureKey, variableKey string, userContext entities.UserContext) (value int, err error) {
189192

190193
val, valueType, err := o.GetFeatureVariable(featureKey, variableKey, userContext)
@@ -198,7 +201,7 @@ func (o *OptimizelyClient) GetFeatureVariableInteger(featureKey, variableKey str
198201
return convertedValue, err
199202
}
200203

201-
// GetFeatureVariableString returns string feature variable value
204+
// GetFeatureVariableString returns the feature variable value of type string associated with the given feature and variable keys.
202205
func (o *OptimizelyClient) GetFeatureVariableString(featureKey, variableKey string, userContext entities.UserContext) (value string, err error) {
203206

204207
value, valueType, err := o.GetFeatureVariable(featureKey, variableKey, userContext)
@@ -211,7 +214,7 @@ func (o *OptimizelyClient) GetFeatureVariableString(featureKey, variableKey stri
211214
return value, err
212215
}
213216

214-
// GetFeatureVariable returns feature as a string along with it's associated type
217+
// GetFeatureVariable returns feature variable as a string along with it's associated type.
215218
func (o *OptimizelyClient) GetFeatureVariable(featureKey, variableKey string, userContext entities.UserContext) (value string, valueType entities.VariableType, err error) {
216219

217220
featureDecisionContext, featureDecision, err := o.getFeatureDecision(featureKey, variableKey, userContext)
@@ -230,7 +233,7 @@ func (o *OptimizelyClient) GetFeatureVariable(featureKey, variableKey string, us
230233
return variable.DefaultValue, variable.Type, err
231234
}
232235

233-
// GetAllFeatureVariables returns all the variables for a given feature along with the enabled state
236+
// GetAllFeatureVariables returns all the variables for a given feature along with the enabled state.
234237
func (o *OptimizelyClient) GetAllFeatureVariables(featureKey string, userContext entities.UserContext) (enabled bool, variableMap map[string]string, err error) {
235238

236239
variableMap = make(map[string]string)
@@ -263,7 +266,7 @@ func (o *OptimizelyClient) GetAllFeatureVariables(featureKey string, userContext
263266
return enabled, variableMap, err
264267
}
265268

266-
// GetVariation returns the key of the variation the user is bucketed into
269+
// GetVariation returns the key of the variation the user is bucketed into. Does not generate impression events.
267270
func (o *OptimizelyClient) GetVariation(experimentKey string, userContext entities.UserContext) (result string, err error) {
268271

269272
defer func() {
@@ -294,7 +297,8 @@ func (o *OptimizelyClient) GetVariation(experimentKey string, userContext entiti
294297
return result, err
295298
}
296299

297-
// Track take and event key with event tags and if the event is part of the config, send to events backend.
300+
// Track generates a conversion event with the given event key if it exists and queues it up to be sent to the Optimizely
301+
// log endpoint for results processing.
298302
func (o *OptimizelyClient) Track(eventKey string, userContext entities.UserContext, eventTags map[string]interface{}) (err error) {
299303

300304
defer func() {
@@ -427,7 +431,7 @@ func (o *OptimizelyClient) getExperimentDecision(experimentKey string, userConte
427431
return decisionContext, experimentDecision, err
428432
}
429433

430-
// GetProjectConfig returns the current ProjectConfig or nil if the instance is not valid
434+
// GetProjectConfig returns the current ProjectConfig or nil if the instance is not valid.
431435
func (o *OptimizelyClient) GetProjectConfig() (projectConfig pkg.ProjectConfig, err error) {
432436

433437
projectConfig, err = o.ConfigManager.GetConfig()
@@ -438,7 +442,7 @@ func (o *OptimizelyClient) GetProjectConfig() (projectConfig pkg.ProjectConfig,
438442
return projectConfig, nil
439443
}
440444

441-
// Close closes the Optimizely instance and stops any ongoing tasks from its children components
445+
// Close closes the Optimizely instance and stops any ongoing tasks from its children components.
442446
func (o *OptimizelyClient) Close() {
443447
o.executionCtx.TerminateAndWait()
444448
}

pkg/client/factory.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/optimizely/go-sdk/pkg/utils"
2929
)
3030

31-
// OptimizelyFactory is used to construct an instance of the OptimizelyClient
31+
// OptimizelyFactory is used to customize and construct an instance of the OptimizelyClient.
3232
type OptimizelyFactory struct {
3333
SDKKey string
3434
Datafile []byte
@@ -41,10 +41,10 @@ type OptimizelyFactory struct {
4141
overrideStore decision.ExperimentOverrideStore
4242
}
4343

44-
// OptionFunc is used to provide custom client configuration to the OptimizelyFactory
44+
// OptionFunc is used to provide custom client configuration to the OptimizelyFactory.
4545
type OptionFunc func(*OptimizelyFactory)
4646

47-
// Client instantiates a new OptimizelyClient with the given options
47+
// Client instantiates a new OptimizelyClient with the given options.
4848
func (f OptimizelyFactory) Client(clientOptions ...OptionFunc) (*OptimizelyClient, error) {
4949
// extract options
5050
for _, opt := range clientOptions {
@@ -112,58 +112,58 @@ func (f OptimizelyFactory) Client(clientOptions ...OptionFunc) (*OptimizelyClien
112112
return appClient, nil
113113
}
114114

115-
// WithPollingConfigManager sets polling config manager on a client
115+
// WithPollingConfigManager sets polling config manager on a client.
116116
func WithPollingConfigManager(sdkKey string, pollingInterval time.Duration, initDataFile []byte) OptionFunc {
117117
return func(f *OptimizelyFactory) {
118118
f.configManager = config.NewPollingProjectConfigManager(sdkKey, config.InitialDatafile(initDataFile),
119119
config.PollingInterval(pollingInterval))
120120
}
121121
}
122122

123-
// WithPollingConfigManagerRequester sets polling config manager on a client
123+
// WithPollingConfigManagerRequester sets polling config manager on a client.
124124
func WithPollingConfigManagerRequester(requester utils.Requester, pollingInterval time.Duration, initDataFile []byte) OptionFunc {
125125
return func(f *OptimizelyFactory) {
126126
f.configManager = config.NewPollingProjectConfigManager("", config.InitialDatafile(initDataFile),
127127
config.PollingInterval(pollingInterval), config.Requester(requester))
128128
}
129129
}
130130

131-
// WithConfigManager sets polling config manager on a client
131+
// WithConfigManager sets polling config manager on a client.
132132
func WithConfigManager(configManager pkg.ProjectConfigManager) OptionFunc {
133133
return func(f *OptimizelyFactory) {
134134
f.configManager = configManager
135135
}
136136
}
137137

138-
// WithCompositeDecisionService sets decision service on a client
138+
// WithCompositeDecisionService sets decision service on a client.
139139
func WithCompositeDecisionService(sdkKey string) OptionFunc {
140140
return func(f *OptimizelyFactory) {
141141
f.decisionService = decision.NewCompositeService(sdkKey)
142142
}
143143
}
144144

145-
// WithDecisionService sets decision service on a client
145+
// WithDecisionService sets decision service on a client.
146146
func WithDecisionService(decisionService decision.Service) OptionFunc {
147147
return func(f *OptimizelyFactory) {
148148
f.decisionService = decisionService
149149
}
150150
}
151151

152-
// WithUserProfileService sets the user profile service on the decision service
152+
// WithUserProfileService sets the user profile service on the decision service.
153153
func WithUserProfileService(userProfileService decision.UserProfileService) OptionFunc {
154154
return func(f *OptimizelyFactory) {
155155
f.userProfileService = userProfileService
156156
}
157157
}
158158

159-
// WithExperimentOverrides sets the experiment override store on the decision service
159+
// WithExperimentOverrides sets the experiment override store on the decision service.
160160
func WithExperimentOverrides(overrideStore decision.ExperimentOverrideStore) OptionFunc {
161161
return func(f *OptimizelyFactory) {
162162
f.overrideStore = overrideStore
163163
}
164164
}
165165

166-
// WithBatchEventProcessor sets event processor on a client
166+
// WithBatchEventProcessor sets event processor on a client.
167167
func WithBatchEventProcessor(batchSize, queueSize int, flushInterval time.Duration) OptionFunc {
168168
return func(f *OptimizelyFactory) {
169169
f.eventProcessor = event.NewBatchEventProcessor(event.WithBatchSize(batchSize),
@@ -178,14 +178,14 @@ func WithEventProcessor(eventProcessor event.Processor) OptionFunc {
178178
}
179179
}
180180

181-
// WithExecutionContext allows user to pass in their own execution context to override the default one in the client
181+
// WithExecutionContext allows user to pass in their own execution context to override the default one in the client.
182182
func WithExecutionContext(executionContext utils.ExecutionCtx) OptionFunc {
183183
return func(f *OptimizelyFactory) {
184184
f.executionCtx = executionContext
185185
}
186186
}
187187

188-
// StaticClient returns a client initialized with a static project config
188+
// StaticClient returns a client initialized with a static project config.
189189
func (f OptimizelyFactory) StaticClient() (*OptimizelyClient, error) {
190190
var configManager pkg.ProjectConfigManager
191191

pkg/config/polling_manager.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ const DatafileURLTemplate = "https://cdn.optimizely.com/datafiles/%s.json"
4545

4646
var cmLogger = logging.GetLogger("PollingConfigManager")
4747

48-
// PollingProjectConfigManager maintains a dynamic copy of the project config
48+
// PollingProjectConfigManager maintains a dynamic copy of the project config by continuously polling for the datafile
49+
// from the Optimizely CDN at a given (configurable) interval.
4950
type PollingProjectConfigManager struct {
5051
requester utils.Requester
5152
pollingInterval time.Duration
@@ -59,7 +60,7 @@ type PollingProjectConfigManager struct {
5960
projectConfig pkg.ProjectConfig
6061
}
6162

62-
// OptionFunc is a type to a proper func
63+
// OptionFunc is used to provide custom configuration to the PollingProjectConfigManager.
6364
type OptionFunc func(*PollingProjectConfigManager)
6465

6566
// Requester is an optional function, sets a passed requester

pkg/decision/composite_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ import (
2929

3030
var csLogger = logging.GetLogger("CompositeDecisionService")
3131

32-
// CompositeService is the entrypoint into the decision service. It provides out of the box decision making for Features and Experiments.
32+
// CompositeService is the entry-point into the decision service. It provides out of the box decision making for Features and Experiments.
3333
type CompositeService struct {
3434
compositeExperimentService ExperimentService
3535
compositeFeatureService FeatureService
3636
notificationCenter notification.Center
3737
}
3838

39-
// CSOptionFunc is used to pass config options into the CompositeService
39+
// CSOptionFunc is used to pass custom config options into the CompositeService.
4040
type CSOptionFunc func(*CompositeService)
4141

4242
// WithCompositeExperimentService sets the composite experiment service on the CompositeService

pkg/event/factory_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ func TestCreateAndSendImpressionEvent(t *testing.T) {
129129

130130
processor.ProcessEvent(impressionUserEvent)
131131

132-
assert.Equal(t, 1, processor.EventsCount())
132+
assert.Equal(t, 1, processor.eventsCount())
133133

134134
time.Sleep(100 * time.Millisecond)
135135

136-
assert.Equal(t, 0, processor.EventsCount())
136+
assert.Equal(t, 0, processor.eventsCount())
137137
}
138138

139139
func TestCreateAndSendConversionEvent(t *testing.T) {
@@ -147,11 +147,11 @@ func TestCreateAndSendConversionEvent(t *testing.T) {
147147

148148
processor.ProcessEvent(conversionUserEvent)
149149

150-
assert.Equal(t, 1, processor.EventsCount())
150+
assert.Equal(t, 1, processor.eventsCount())
151151

152152
time.Sleep(100 * time.Millisecond)
153153

154-
assert.Equal(t, 0, processor.EventsCount())
154+
assert.Equal(t, 0, processor.eventsCount())
155155
}
156156

157157
func TestCreateConversionEventRevenue(t *testing.T) {

0 commit comments

Comments
 (0)