Skip to content

Commit b4f1751

Browse files
committed
fix lint errors
1 parent 9e9b82f commit b4f1751

File tree

6 files changed

+42
-39
lines changed

6 files changed

+42
-39
lines changed

pkg/cmab/client.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,34 @@ const (
4444
DefaultBackoffMultiplier = 2.0
4545
)
4646

47-
// CMABAttribute represents an attribute in a CMAB request
48-
type CMABAttribute struct {
47+
// Attribute represents an attribute in a CMAB request
48+
type Attribute struct {
4949
ID string `json:"id"`
5050
Value interface{} `json:"value"`
5151
Type string `json:"type"`
5252
}
5353

54-
// CMABInstance represents an instance in a CMAB request
55-
type CMABInstance struct {
56-
VisitorID string `json:"visitorId"`
57-
ExperimentID string `json:"experimentId"`
58-
Attributes []CMABAttribute `json:"attributes"`
59-
CmabUUID string `json:"cmabUUID"`
54+
// Instance represents an instance in a CMAB request
55+
type Instance struct {
56+
VisitorID string `json:"visitorId"`
57+
ExperimentID string `json:"experimentId"`
58+
Attributes []Attribute `json:"attributes"`
59+
CmabUUID string `json:"cmabUUID"`
6060
}
6161

62-
// CMABRequest represents a request to the CMAB API
63-
type CMABRequest struct {
64-
Instances []CMABInstance `json:"instances"`
62+
// Request represents a request to the CMAB API
63+
type Request struct {
64+
Instances []Instance `json:"instances"`
6565
}
6666

67-
// CMABPrediction represents a prediction in a CMAB response
68-
type CMABPrediction struct {
67+
// Prediction represents a prediction in a CMAB response
68+
type Prediction struct {
6969
VariationID string `json:"variation_id"`
7070
}
7171

72-
// CMABResponse represents a response from the CMAB API
73-
type CMABResponse struct {
74-
Predictions []CMABPrediction `json:"predictions"`
72+
// Response represents a response from the CMAB API
73+
type Response struct {
74+
Predictions []Prediction `json:"predictions"`
7575
}
7676

7777
// RetryConfig defines configuration for retry behavior
@@ -142,18 +142,18 @@ func (c *DefaultCmabClient) FetchDecision(
142142
url := fmt.Sprintf(CMABPredictionEndpoint, ruleID)
143143

144144
// Convert attributes to CMAB format
145-
cmabAttributes := make([]CMABAttribute, 0, len(attributes))
145+
cmabAttributes := make([]Attribute, 0, len(attributes))
146146
for key, value := range attributes {
147-
cmabAttributes = append(cmabAttributes, CMABAttribute{
147+
cmabAttributes = append(cmabAttributes, Attribute{
148148
ID: key,
149149
Value: value,
150150
Type: "custom_attribute",
151151
})
152152
}
153153

154154
// Create the request body
155-
requestBody := CMABRequest{
156-
Instances: []CMABInstance{
155+
requestBody := Request{
156+
Instances: []Instance{
157157
{
158158
VisitorID: userID,
159159
ExperimentID: ruleID,
@@ -248,7 +248,7 @@ func (c *DefaultCmabClient) doFetch(ctx context.Context, url string, bodyBytes [
248248
}
249249

250250
// Parse response
251-
var cmabResponse CMABResponse
251+
var cmabResponse Response
252252
if err := json.Unmarshal(respBody, &cmabResponse); err != nil {
253253
return "", fmt.Errorf("failed to unmarshal CMAB response: %w", err)
254254
}
@@ -263,6 +263,6 @@ func (c *DefaultCmabClient) doFetch(ctx context.Context, url string, bodyBytes [
263263
}
264264

265265
// validateResponse validates the CMAB response
266-
func (c *DefaultCmabClient) validateResponse(response CMABResponse) bool {
266+
func (c *DefaultCmabClient) validateResponse(response Response) bool {
267267
return len(response.Predictions) > 0 && response.Predictions[0].VariationID != ""
268268
}

pkg/cmab/client_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestDefaultCmabClient_FetchDecision(t *testing.T) {
6565
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
6666

6767
// Parse request body
68-
var requestBody CMABRequest
68+
var requestBody Request
6969
err := json.NewDecoder(r.Body).Decode(&requestBody)
7070
assert.NoError(t, err)
7171

@@ -80,7 +80,7 @@ func TestDefaultCmabClient_FetchDecision(t *testing.T) {
8080
assert.Len(t, instance.Attributes, 5)
8181

8282
// Create a map for easier attribute checking
83-
attrMap := make(map[string]CMABAttribute)
83+
attrMap := make(map[string]Attribute)
8484
for _, attr := range instance.Attributes {
8585
attrMap[attr.ID] = attr
8686
assert.Equal(t, "custom_attribute", attr.Type)
@@ -109,8 +109,8 @@ func TestDefaultCmabClient_FetchDecision(t *testing.T) {
109109
// Return response
110110
w.Header().Set("Content-Type", "application/json")
111111
w.WriteHeader(http.StatusOK)
112-
response := CMABResponse{
113-
Predictions: []CMABPrediction{
112+
response := Response{
113+
Predictions: []Prediction{
114114
{
115115
VariationID: "var123",
116116
},
@@ -167,7 +167,7 @@ func TestDefaultCmabClient_FetchDecision_WithRetry(t *testing.T) {
167167
body, err := io.ReadAll(r.Body)
168168
assert.NoError(t, err)
169169

170-
var requestBody CMABRequest
170+
var requestBody Request
171171
err = json.Unmarshal(body, &requestBody)
172172
assert.NoError(t, err)
173173

@@ -187,8 +187,8 @@ func TestDefaultCmabClient_FetchDecision_WithRetry(t *testing.T) {
187187
// Return success response on third attempt
188188
w.Header().Set("Content-Type", "application/json")
189189
w.WriteHeader(http.StatusOK)
190-
response := CMABResponse{
191-
Predictions: []CMABPrediction{
190+
response := Response{
191+
Predictions: []Prediction{
192192
{
193193
VariationID: "var123",
194194
},
@@ -442,8 +442,8 @@ func TestDefaultCmabClient_ExponentialBackoff(t *testing.T) {
442442
// Return success response
443443
w.Header().Set("Content-Type", "application/json")
444444
w.WriteHeader(http.StatusOK)
445-
response := CMABResponse{
446-
Predictions: []CMABPrediction{
445+
response := Response{
446+
Predictions: []Prediction{
447447
{
448448
VariationID: "var123",
449449
},
@@ -649,8 +649,8 @@ func TestDefaultCmabClient_FetchDecision_ContextCancellation(t *testing.T) {
649649

650650
w.Header().Set("Content-Type", "application/json")
651651
w.WriteHeader(http.StatusOK)
652-
response := CMABResponse{
653-
Predictions: []CMABPrediction{
652+
response := Response{
653+
Predictions: []Prediction{
654654
{
655655
VariationID: "var123",
656656
},

pkg/cmab/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ type DefaultCmabService struct {
3939
logger logging.OptimizelyLogProducer
4040
}
4141

42-
// CmabServiceOptions defines options for creating a CMAB service
43-
type CmabServiceOptions struct {
42+
// ServiceOptions defines options for creating a CMAB service
43+
type ServiceOptions struct {
4444
Logger logging.OptimizelyLogProducer
4545
CmabCache cache.CacheWithRemove
4646
CmabClient Client
4747
}
4848

4949
// NewDefaultCmabService creates a new instance of DefaultCmabService
50-
func NewDefaultCmabService(options CmabServiceOptions) *DefaultCmabService {
50+
func NewDefaultCmabService(options ServiceOptions) *DefaultCmabService {
5151
logger := options.Logger
5252
if logger == nil {
5353
logger = logging.GetLogger("", "DefaultCmabService")

pkg/cmab/service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (s *CmabServiceTestSuite) SetupTest() {
241241
s.mockConfig = new(MockProjectConfig)
242242

243243
// Set up the CMAB service
244-
s.cmabService = NewDefaultCmabService(CmabServiceOptions{
244+
s.cmabService = NewDefaultCmabService(ServiceOptions{
245245
Logger: logging.GetLogger("test", "CmabService"),
246246
CmabCache: s.mockCache,
247247
CmabClient: s.mockClient,
@@ -725,7 +725,7 @@ func (s *CmabServiceTestSuite) TestGetCacheKey() {
725725

726726
func (s *CmabServiceTestSuite) TestNewDefaultCmabService() {
727727
// Test with default options
728-
service := NewDefaultCmabService(CmabServiceOptions{})
728+
service := NewDefaultCmabService(ServiceOptions{})
729729

730730
// Only check that the service is created, not the specific fields
731731
s.NotNil(service)

pkg/cmab/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* limitations under the License. *
1515
***************************************************************************/
1616

17+
// Package cmab provides functionality for Contextual Multi-Armed Bandit (CMAB)
18+
// decision-making, including client and service implementations for making and
19+
// handling CMAB requests and responses.
1720
package cmab
1821

1922
import (

pkg/decision/composite_experiment_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func NewCompositeExperimentService(sdkKey string, options ...CESOptionFunc) *Com
106106
cmabClientAdapter := &cmabClientAdapter{client: defaultCmabClient}
107107

108108
// Create CMAB service options
109-
cmabServiceOptions := cmab.CmabServiceOptions{
109+
cmabServiceOptions := cmab.ServiceOptions{
110110
CmabCache: cmabCache,
111111
CmabClient: cmabClientAdapter,
112112
Logger: logging.GetLogger(sdkKey, "DefaultCmabService"),

0 commit comments

Comments
 (0)