From 4d68d51b0bcaef76a26f701eba138b6598e09154 Mon Sep 17 00:00:00 2001 From: Matjaz Pirnovar Date: Fri, 10 Mar 2023 15:48:04 -0800 Subject: [PATCH] [FSSDK-8957] Update non-code path resources for FX (#366) * updated README * changes to other files * clenup * PR fixes * remove ampty sections, update code sample * updtae code sample * updtae other code sample --- README.md | 123 +++++++++++++----- .../go-sdk/040 - optimizelyconfig-go.md | 2 +- .../go-sdk/070 - event-batching-go.md | 2 +- pkg/odp/utils/constants.go | 2 +- 4 files changed, 97 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 7b3f88d56..502f3b5e9 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,30 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/optimizely/go-sdk)](https://goreportcard.com/report/github.com/optimizely/go-sdk) [![Coverage Status](https://coveralls.io/repos/github/optimizely/go-sdk/badge.svg?branch=master)](https://coveralls.io/github/optimizely/go-sdk?branch=master) -## Installation -### Install from github: +This repository houses the Go SDK for use with Optimizely Feature Experimentation and Optimizely Full Stack (legacy). + +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). + +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. + +## Get Started + +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. + +### Requirements + +Requires Golang version 1.13 or higher. + +### Install the SDK + +#### Install from github: ```$sh go get github.com/optimizely/go-sdk ``` -### Install from source: +#### Install from source: ```$sh go get github.com/optimizely/go-sdk cd $GOPATH/src/github.com/optimizely/go-sdk @@ -21,7 +36,7 @@ go install NOTE: 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: -### Install using go.mod: +#### Install using go.mod: ``` module mymodule @@ -49,46 +64,72 @@ go get github.com/optimizely/go-sdk/pkg ``` will install it as a package to pkg directory, rather than src directory. It could be useful for future development and vendoring. -## Usage -### Instantiation -To start using the SDK, create an instance using our factory method: +## Use the Go SDK + +See the example file in examples/main.go. + +### Initialization ``` import optly "github.com/optimizely/go-sdk" import "github.com/optimizely/go-sdk/client" -// Simple one-line initialization with the SDK key -client, err := optly.Client("SDK_KEY") +// Simple one-line initialization with the SDK key    +optlyClient, err := optly.Client("SDK_KEY")    -// You can also instantiate with a hard-coded datafile using our client factory method -optimizelyFactory := &client.OptimizelyFactory{ - Datafile: []byte("datafile_string"), +// You can also instantiate with a hard-coded datafile using our client factory method    +optimizelyFactory := &client.OptimizelyFactory {        + Datafile: []byte("datafile_string"),    +}    +optlyClient, err = optimizelyFactory.Client() +``` +### Make Decisions +``` +import ( + optly "github.com/optimizely/go-sdk" +) + +// instantiate a client +client, err := optly.Client("SDK_KEY") + +// User attributes are optional and used for targeting and results segmentation +attributes := map[string]interface{}{ + "state": "California", + "likes_donuts": true, +} + +user := client.CreateUserContext("optimizely end user", attributes) +options := []decide.OptimizelyDecideOptions{decide.IncludeReasons} + +decision := user.Decide("my_flag", options) +var variationKey string +if variationKey = decision.VariationKey; variationKey == "" { + fmt.Printf("[decide] error: %v", decision.Reasons) + return +} + +if variationKey == "control" { + // Execute code for control variation +} else if variationKey == "treatment" { + // Execute code for treatment variation } +``` -client, err = optimizelyFactory.Client() +## SDK Development -``` +### Unit Tests -### Feature Rollouts +Run +``` +make test ``` -import ( - optly "github.com/optimizely/go-sdk" -) -// instantiate a client -client, err := optly.Client("SDK_KEY") +### Contributing -// User attributes are optional and used for targeting and results segmentation -atributes := map[string]interface{}{ - "state": "California", - "likes_donuts": true, -}, -user := optly.UserContext("optimizely end user", attributes) -enabled, _ := client.IsFeatureEnabled("binary_feature", user) -``` +Please see [CONTRIBUTING](https://github.com/optimizely/go-sdk/blob/master/CONTRIBUTING.md). -## Credits +### Credits This software is distributed with code from the following open source projects: @@ -119,3 +160,27 @@ License (BSD): https://github.com/pkg/profile/blob/master/LICENSE sync Copyright (c) 2009 The Go Authors. All rights reserved. https://github.com/golang/sync/blob/master/LICENSE + +### Other Optimizely SDKs + +- Agent - https://github.com/optimizely/agent + +- Android - https://github.com/optimizely/android-sdk + +- C# - https://github.com/optimizely/csharp-sdk + +- Flutter - https://github.com/optimizely/optimizely-flutter-sdk + +- Java - https://github.com/optimizely/java-sdk + +- JavaScript - https://github.com/optimizely/javascript-sdk + +- PHP - https://github.com/optimizely/php-sdk + +- Python - https://github.com/optimizely/python-sdk + +- React - https://github.com/optimizely/react-sdk + +- Ruby - https://github.com/optimizely/ruby-sdk + +- Swift - https://github.com/optimizely/swift-sdk \ No newline at end of file diff --git a/docs/readme-sync/sdk-reference-guides/go-sdk/040 - optimizelyconfig-go.md b/docs/readme-sync/sdk-reference-guides/go-sdk/040 - optimizelyconfig-go.md index f8535bcdc..02e5b71b9 100644 --- a/docs/readme-sync/sdk-reference-guides/go-sdk/040 - optimizelyconfig-go.md +++ b/docs/readme-sync/sdk-reference-guides/go-sdk/040 - optimizelyconfig-go.md @@ -8,7 +8,7 @@ updatedAt: "2020-01-28T21:53:26.607Z" --- ### Overview -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". +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". In this document, we extend our public APIs to define data models and access methods, which clients can use to access project configuration data. diff --git a/docs/readme-sync/sdk-reference-guides/go-sdk/070 - event-batching-go.md b/docs/readme-sync/sdk-reference-guides/go-sdk/070 - event-batching-go.md index 9d177dd3c..bf4c7ae2d 100644 --- a/docs/readme-sync/sdk-reference-guides/go-sdk/070 - event-batching-go.md +++ b/docs/readme-sync/sdk-reference-guides/go-sdk/070 - event-batching-go.md @@ -6,7 +6,7 @@ hidden: true createdAt: "2019-10-29T23:36:28.978Z" updatedAt: "2020-01-16T20:42:04.941Z" --- -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. +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. 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. diff --git a/pkg/odp/utils/constants.go b/pkg/odp/utils/constants.go index 6f216cfe7..b5b0b9301 100644 --- a/pkg/odp/utils/constants.go +++ b/pkg/odp/utils/constants.go @@ -28,7 +28,7 @@ const OdpAPIKeyHeader = "x-api-key" // OdpEventType holds the value for the odp event type const OdpEventType = "fullstack" -// OdpFSUserIDKey holds the key for the odp fullstack userID +// OdpFSUserIDKey holds the key for the odp fullstack/feature experimentation userID const OdpFSUserIDKey = "fs_user_id" // OdpActionIdentified holds the value for identified action type