Skip to content

Commit 6a2dfcf

Browse files
committed
adding cherry-pick becasue of the merge conflict
1 parent abd8d8a commit 6a2dfcf

File tree

4 files changed

+152
-31
lines changed

4 files changed

+152
-31
lines changed

README.md

+94-29
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,30 @@
33
[![Go Report Card](https://goreportcard.com/badge/github.com/optimizely/go-sdk)](https://goreportcard.com/report/github.com/optimizely/go-sdk)
44
[![Coverage Status](https://coveralls.io/repos/github/optimizely/go-sdk/badge.svg?branch=master)](https://coveralls.io/github/optimizely/go-sdk?branch=master)
55

6-
## Installation
76

8-
### Install from github:
7+
This repository houses the Go SDK for use with Optimizely Feature Experimentation and Optimizely Full Stack (legacy).
8+
9+
Optimizely Feature Experimentation is an A/B testing and feature management tool for product development teams that enables you to experiment at every step. Using Optimizely Feature Experimentation allows for every feature on your roadmap to be an opportunity to discover hidden insights. Learn more at [Optimizely.com](https://www.optimizely.com/products/experiment/feature-experimentation/), or see the [developer documentation](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/welcome).
10+
11+
Optimizely Rollouts is [free feature flags](https://www.optimizely.com/free-feature-flagging/) for development teams. You can easily roll out and roll back features in any application without code deploys, mitigating risk for every feature on your roadmap.
12+
13+
## Get Started
14+
15+
Refer to the [Go SDK's developer documentation](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/go-sdk) for detailed instructions on getting started with using the SDK.
16+
17+
### Requirements
18+
19+
Requires Golang version 1.13 or higher.
20+
21+
### Install the SDK
22+
23+
#### Install from github:
924

1025
```$sh
1126
go get github.com/optimizely/go-sdk
1227
```
1328

14-
### Install from source:
29+
#### Install from source:
1530
```$sh
1631
go get github.com/optimizely/go-sdk
1732
cd $GOPATH/src/github.com/optimizely/go-sdk
@@ -21,7 +36,7 @@ go install
2136
NOTE:
2237
We practice trunk-based development, and as such our default branch, `master` might not always be the most stable. We do tag releases on Github and you can pin your installation to those particular release versions. One way to do this is to use [*Go Modules*](https://blog.golang.org/using-go-modules) for managing external dependencies:
2338

24-
### Install using go.mod:
39+
#### Install using go.mod:
2540

2641
```
2742
module mymodule
@@ -49,46 +64,72 @@ go get github.com/optimizely/go-sdk/pkg
4964
```
5065
will install it as a package to pkg directory, rather than src directory. It could be useful for future development and vendoring.
5166

52-
## Usage
5367

54-
### Instantiation
55-
To start using the SDK, create an instance using our factory method:
68+
## Use the Go SDK
69+
70+
See the example file in examples/main.go.
71+
72+
### Initialization
5673

5774
```
5875
import optly "github.com/optimizely/go-sdk"
5976
import "github.com/optimizely/go-sdk/client"
6077
61-
// Simple one-line initialization with the SDK key
62-
client, err := optly.Client("SDK_KEY")
78+
// Simple one-line initialization with the SDK key   
79+
optlyClient, err := optly.Client("SDK_KEY")   
6380
64-
// You can also instantiate with a hard-coded datafile using our client factory method
65-
optimizelyFactory := &client.OptimizelyFactory{
66-
Datafile: []byte("datafile_string"),
81+
// You can also instantiate with a hard-coded datafile using our client factory method   
82+
optimizelyFactory := &client.OptimizelyFactory {       
83+
Datafile: []byte("datafile_string"),   
84+
}   
85+
optlyClient, err = optimizelyFactory.Client()
86+
```
87+
### Make Decisions
88+
```
89+
import (
90+
optly "github.com/optimizely/go-sdk"
91+
)
92+
93+
// instantiate a client
94+
client, err := optly.Client("SDK_KEY")
95+
96+
// User attributes are optional and used for targeting and results segmentation
97+
attributes := map[string]interface{}{
98+
"state": "California",
99+
"likes_donuts": true,
100+
}
101+
102+
user := client.CreateUserContext("optimizely end user", attributes)
103+
options := []decide.OptimizelyDecideOptions{decide.IncludeReasons}
104+
105+
decision := user.Decide("my_flag", options)
106+
var variationKey string
107+
if variationKey = decision.VariationKey; variationKey == "" {
108+
fmt.Printf("[decide] error: %v", decision.Reasons)
109+
return
110+
}
111+
112+
if variationKey == "control" {
113+
// Execute code for control variation
114+
} else if variationKey == "treatment" {
115+
// Execute code for treatment variation
67116
}
117+
```
68118

69-
client, err = optimizelyFactory.Client()
119+
## SDK Development
70120

71-
```
121+
### Unit Tests
72122

73-
### Feature Rollouts
123+
Run
124+
```
125+
make test
74126
```
75-
import (
76-
optly "github.com/optimizely/go-sdk"
77-
)
78127

79-
// instantiate a client
80-
client, err := optly.Client("SDK_KEY")
128+
### Contributing
81129

82-
// User attributes are optional and used for targeting and results segmentation
83-
atributes := map[string]interface{}{
84-
"state": "California",
85-
"likes_donuts": true,
86-
},
87-
user := optly.UserContext("optimizely end user", attributes)
88-
enabled, _ := client.IsFeatureEnabled("binary_feature", user)
89-
```
130+
Please see [CONTRIBUTING](https://github.com/optimizely/go-sdk/blob/master/CONTRIBUTING.md).
90131

91-
## Credits
132+
### Credits
92133

93134
This software is distributed with code from the following open source projects:
94135

@@ -119,3 +160,27 @@ License (BSD): https://github.com/pkg/profile/blob/master/LICENSE
119160
sync
120161
Copyright (c) 2009 The Go Authors. All rights reserved.
121162
https://github.com/golang/sync/blob/master/LICENSE
163+
164+
### Other Optimizely SDKs
165+
166+
- Agent - https://github.com/optimizely/agent
167+
168+
- Android - https://github.com/optimizely/android-sdk
169+
170+
- C# - https://github.com/optimizely/csharp-sdk
171+
172+
- Flutter - https://github.com/optimizely/optimizely-flutter-sdk
173+
174+
- Java - https://github.com/optimizely/java-sdk
175+
176+
- JavaScript - https://github.com/optimizely/javascript-sdk
177+
178+
- PHP - https://github.com/optimizely/php-sdk
179+
180+
- Python - https://github.com/optimizely/python-sdk
181+
182+
- React - https://github.com/optimizely/react-sdk
183+
184+
- Ruby - https://github.com/optimizely/ruby-sdk
185+
186+
- Swift - https://github.com/optimizely/swift-sdk

docs/readme-sync/sdk-reference-guides/go-sdk/040 - optimizelyconfig-go.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ updatedAt: "2020-01-28T21:53:26.607Z"
88
---
99
### Overview
1010

11-
Full Stack SDKs open a well-defined set of public APIs, hiding all implementation details. However, some clients may need access to project configuration data within the "datafile".
11+
Optimizely Feature Experimentation and Optimizely Full Stack (legacy) SDKs open a well-defined set of public APIs, hiding all implementation details. However, some clients may need access to project configuration data within the "datafile".
1212

1313
In this document, we extend our public APIs to define data models and access methods, which clients can use to access project configuration data.
1414

docs/readme-sync/sdk-reference-guides/go-sdk/070 - event-batching-go.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ hidden: true
66
createdAt: "2019-10-29T23:36:28.978Z"
77
updatedAt: "2020-01-16T20:42:04.941Z"
88
---
9-
The [Optimizely Full Stack Go SDK](https://github.com/optimizely/go-sdk) batches impression and conversion events into a single payload before sending it to Optimizely. This is achieved through an SDK component called the event processor.
9+
The [Optimizely Feature Experimentation Go SDK](https://github.com/optimizely/go-sdk) batches impression and conversion events into a single payload before sending it to Optimizely. This is achieved through an SDK component called the event processor.
1010

1111
Event batching has the advantage of reducing the number of outbound requests to Optimizely depending on how you define, configure, and use the event processor. It means less network traffic for the same number of Impression and conversion events tracked.
1212

pkg/odp/utils/constants.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/****************************************************************************
2+
* Copyright 2022, Optimizely, Inc. and contributors *
3+
* *
4+
* Licensed under the Apache License, Version 2.0 (the "License"); *
5+
* you may not use this file except in compliance with the License. *
6+
* You may obtain a copy of the License at *
7+
* *
8+
* https://www.apache.org/licenses/LICENSE-2.0 *
9+
* *
10+
* Unless required by applicable law or agreed to in writing, software *
11+
* distributed under the License is distributed on an "AS IS" BASIS, *
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13+
* See the License for the specific language governing permissions and *
14+
* limitations under the License. *
15+
***************************************************************************/
16+
17+
// Package utils //
18+
package utils
19+
20+
import "time"
21+
22+
// ODPEventsAPIEndpointPath defines the endpoint path for events api
23+
const ODPEventsAPIEndpointPath = "/v3/events"
24+
25+
// OdpAPIKeyHeader defines key for designating the ODP API public key
26+
const OdpAPIKeyHeader = "x-api-key"
27+
28+
// OdpEventType holds the value for the odp event type
29+
const OdpEventType = "fullstack"
30+
31+
// OdpFSUserIDKey holds the key for the odp fullstack/feature experimentation userID
32+
const OdpFSUserIDKey = "fs_user_id"
33+
34+
// OdpActionIdentified holds the value for identified action type
35+
const OdpActionIdentified = "identified"
36+
37+
// DefaultBatchSize holds the default value for the batch size
38+
const DefaultBatchSize = 10
39+
40+
// DefaultEventQueueSize holds the default value for the event queue size
41+
const DefaultEventQueueSize = 10000
42+
43+
// DefaultEventFlushInterval holds the default value for the event flush interval
44+
const DefaultEventFlushInterval = 1 * time.Second
45+
46+
// DefaultSegmentsCacheSize holds the default value for the segments cache size
47+
const DefaultSegmentsCacheSize = 10000
48+
49+
// DefaultSegmentsCacheTimeout holds the default value for the segments cache timeout
50+
const DefaultSegmentsCacheTimeout = 10 * time.Minute // 10 minutes
51+
52+
// DefaultOdpEventTimeout holds the default value for the odp event timeout
53+
const DefaultOdpEventTimeout = 10 * time.Second
54+
55+
// DefaultSegmentFetchTimeout holds the default value for the segment fetch timeout
56+
const DefaultSegmentFetchTimeout = 10 * time.Second

0 commit comments

Comments
 (0)