Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ testify
Copyright (c) 2012-2018 Mat Ryer and Tyler Bunnell.
License (MIT): https://github.com/stretchr/testify/blob/master/LICENSE

json-iterator
Copyright (c) 2016 json-iterator
License (MIT): https://github.com/json-iterator/go/blob/master/LICENSE
go-json
Copyright (c) 2020 go-json
License (MIT): https://github.com/goccy/go-json/blob/master/LICENSE

go-reflect
Copyright (c) 2020 go-reflect
License (MIT): https://github.com/goccy/go-reflect/blob/master/LICENSE

subset
Copyright (c) 2015, Facebook, Inc. All rights reserved.
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module github.com/optimizely/go-sdk
go 1.13

require (
github.com/goccy/go-json v0.10.0
github.com/goccy/go-reflect v1.2.0
github.com/google/uuid v1.1.1
github.com/hashicorp/go-multierror v1.1.0
github.com/json-iterator/go v1.1.12
github.com/pkg/errors v0.8.1
github.com/pkg/profile v1.3.0
github.com/stretchr/testify v1.4.0
Expand Down
15 changes: 5 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-reflect v1.2.0 h1:O0T8rZCuNmGXewnATuKYnkL0xm6o8UNOJZd/gOkb9ms=
github.com/goccy/go-reflect v1.2.0/go.mod h1:n0oYZn8VcV2CkWTxi8B9QjkCoq6GTtCEdfmR66YhFtE=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.3.0 h1:OQIvuDgm00gWVWGTf4m4mCt6W1/0YqU7Ntg0mySWgaI=
Expand All @@ -22,7 +18,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/twmb/murmur3 v1.0.0 h1:MLMwMEQRKsu94uJnoveYjjHmcLwI3HNcWXP4LJuNe3I=
Expand Down
8 changes: 5 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
package client

import (
"encoding/json"
"errors"
"fmt"
"reflect"
"runtime/debug"
"strconv"

"github.com/goccy/go-reflect"

"github.com/goccy/go-json"

"github.com/optimizely/go-sdk/pkg/config"
"github.com/optimizely/go-sdk/pkg/decide"
"github.com/optimizely/go-sdk/pkg/decision"
Expand Down Expand Up @@ -1085,5 +1087,5 @@ func (o *OptimizelyClient) getDecisionVariableMap(feature entities.Feature, vari
}

func isNil(v interface{}) bool {
return v == nil || (reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil())
return v == nil || (reflect.ValueNoEscapeOf(v).Kind() == reflect.Ptr && reflect.ValueNoEscapeOf(v).IsNil())
}
2 changes: 1 addition & 1 deletion pkg/config/datafileprojectconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestNewDatafileProjectConfigNil(t *testing.T) {

func TestNewDatafileProjectConfigNotNil(t *testing.T) {
dpc := DatafileProjectConfig{accountID: "123", revision: "1", projectID: "12345", sdkKey: "a", environmentKey: "production", eventMap: map[string]entities.Event{"event_single_targeted_exp": {Key: "event_single_targeted_exp"}}, attributeMap: map[string]entities.Attribute{"10401066170": {ID: "10401066170"}}, integrations: []entities.Integration{{PublicKey: "123", Host: "www.123.com", Key: "odp"}}}
jsonDatafileStr := `{"accountID":"123","revision":"1","projectId":"12345","version":"4","sdkKey":"a","environmentKey":"production","events":[{"key":"event_single_targeted_exp"}],"attributes":[{"id":"10401066170"}],"integrations": [{"publicKey": "123", "host": "www.123.com", "key": "odp"}]}`
jsonDatafileStr := `{"accountId":"123","revision":"1","projectId":"12345","version":"4","sdkKey":"a","environmentKey":"production","events":[{"key":"event_single_targeted_exp"}],"attributes":[{"id":"10401066170"}],"integrations": [{"publicKey": "123", "host": "www.123.com", "key": "odp"}]}`
jsonDatafile := []byte(jsonDatafileStr)
projectConfig, err := NewDatafileProjectConfig(jsonDatafile, logging.GetLogger("", "DatafileProjectConfig"))
assert.Nil(t, err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/datafileprojectconfig/entities/entities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package entities

import (
"encoding/json"
"testing"

"github.com/goccy/go-json"

"github.com/stretchr/testify/assert"
)

Expand Down
6 changes: 2 additions & 4 deletions pkg/config/datafileprojectconfig/json_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
package datafileprojectconfig

import (
"github.com/optimizely/go-sdk/pkg/config/datafileprojectconfig/entities"
"github.com/goccy/go-json"

"github.com/json-iterator/go"
"github.com/optimizely/go-sdk/pkg/config/datafileprojectconfig/entities"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

// Parse parses the raw json datafile
func Parse(jsonDatafile []byte) (*entities.Datafile, error) {

Expand Down
11 changes: 6 additions & 5 deletions pkg/config/datafileprojectconfig/mappers/condition_trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ package mappers

import (
"errors"
"reflect"

jsoniter "github.com/json-iterator/go"
"github.com/goccy/go-reflect"

"github.com/goccy/go-json"

"github.com/optimizely/go-sdk/pkg/decision/evaluator/matchers"
"github.com/optimizely/go-sdk/pkg/entities"
)

var errEmptyTree = errors.New("empty tree")
var json = jsoniter.ConfigCompatibleWithStandardLibrary

// OperatorType defines logical operator for conditions
type OperatorType string
Expand All @@ -47,7 +48,7 @@ func buildConditionTree(conditions interface{}) (conditionTree *entities.TreeNod
return
}
odpSegments = []string{}
value := reflect.ValueOf(parsedConditions)
value := reflect.ValueNoEscapeOf(parsedConditions)
visited := make(map[interface{}]bool)

conditionTree = &entities.TreeNode{}
Expand Down Expand Up @@ -150,7 +151,7 @@ func createLeafCondition(typedV map[string]interface{}, node *entities.TreeNode)
// Takes the conditions array from the audience in the datafile and turns it into a condition tree
func buildAudienceConditionTree(conditions interface{}) (conditionTree *entities.TreeNode, err error) {

value := reflect.ValueOf(conditions)
value := reflect.ValueNoEscapeOf(conditions)
visited := make(map[interface{}]bool)

conditionTree = &entities.TreeNode{Operator: "or"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package mappers
import (
"testing"

"github.com/goccy/go-json"

datafileConfig "github.com/optimizely/go-sdk/pkg/config/datafileprojectconfig/entities"
"github.com/optimizely/go-sdk/pkg/entities"
"github.com/stretchr/testify/assert"
Expand Down
1 change: 1 addition & 0 deletions pkg/config/datafileprojectconfig/mappers/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package mappers
import (
"testing"

"github.com/goccy/go-json"
datafileEntities "github.com/optimizely/go-sdk/pkg/config/datafileprojectconfig/entities"
"github.com/optimizely/go-sdk/pkg/entities"
"github.com/stretchr/testify/assert"
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/datafileprojectconfig/mappers/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package mappers
import (
"testing"

jsoniter "github.com/json-iterator/go"
"github.com/goccy/go-json"

datafileEntities "github.com/optimizely/go-sdk/pkg/config/datafileprojectconfig/entities"
"github.com/optimizely/go-sdk/pkg/entities"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -61,7 +62,6 @@ func TestMapExperiments(t *testing.T) {
}`

var rawExperiment datafileEntities.Experiment
var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal([]byte(testExperimentString), &rawExperiment)

rawExperiments := []datafileEntities.Experiment{rawExperiment}
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/datafileprojectconfig/mappers/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package mappers
import (
"testing"

jsoniter "github.com/json-iterator/go"
"github.com/goccy/go-json"

datafileEntities "github.com/optimizely/go-sdk/pkg/config/datafileprojectconfig/entities"
"github.com/optimizely/go-sdk/pkg/entities"
"github.com/stretchr/testify/assert"
Expand All @@ -35,7 +36,6 @@ func TestMapFeatures(t *testing.T) {
}`

var rawFeatureFlag datafileEntities.FeatureFlag
var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal([]byte(testFeatureFlagString), &rawFeatureFlag)

rawFeatureFlags := []datafileEntities.FeatureFlag{rawFeatureFlag}
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/datafileprojectconfig/mappers/rollout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package mappers
import (
"testing"

"github.com/goccy/go-json"

datafileEntities "github.com/optimizely/go-sdk/pkg/config/datafileprojectconfig/entities"
"github.com/optimizely/go-sdk/pkg/entities"
"github.com/stretchr/testify/assert"
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/optimizely_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
package config

import (
"encoding/json"
"fmt"
"strings"

"github.com/goccy/go-json"

"github.com/optimizely/go-sdk/pkg/config/datafileprojectconfig/mappers"
"github.com/optimizely/go-sdk/pkg/entities"
)
Expand Down
6 changes: 4 additions & 2 deletions pkg/config/optimizely_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package config

import (
"encoding/json"
"io/ioutil"
"reflect"
"testing"

"github.com/goccy/go-reflect"

"github.com/goccy/go-json"

"github.com/stretchr/testify/suite"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/decision/evaluator/matchers/utils/to_float.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Package utils //
package utils

import "reflect"
import "github.com/goccy/go-reflect"

// ToFloat attempts to convert the given value to a float
func ToFloat(value interface{}) (float64, bool) {
Expand All @@ -26,7 +26,7 @@ func ToFloat(value interface{}) (float64, bool) {
return 0, false
}
var floatType = reflect.TypeOf(float64(0))
v := reflect.ValueOf(value)
v := reflect.ValueNoEscapeOf(value)
v = reflect.Indirect(v)

if v.Type().String() == "float64" || v.Type().ConvertibleTo(floatType) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/event/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
package event

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"

"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
)

func TestSnapshotHasOptionalDecisions(t *testing.T) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/odp/event/event_api_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
package event

import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"time"

"github.com/goccy/go-reflect"

"github.com/goccy/go-json"

"github.com/optimizely/go-sdk/pkg/odp/utils"
pkgUtils "github.com/optimizely/go-sdk/pkg/utils"
"github.com/stretchr/testify/suite"
Expand Down
3 changes: 2 additions & 1 deletion pkg/odp/segment/segment_api_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
package segment

import (
"encoding/json"
"errors"
"fmt"
"net/url"
"strings"

"github.com/goccy/go-json"

"github.com/optimizely/go-sdk/pkg/logging"
"github.com/optimizely/go-sdk/pkg/odp/utils"
pkgUtils "github.com/optimizely/go-sdk/pkg/utils"
Expand Down
3 changes: 2 additions & 1 deletion pkg/odp/segment/segment_api_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"time"

"github.com/goccy/go-reflect"

"github.com/optimizely/go-sdk/pkg/logging"
"github.com/optimizely/go-sdk/pkg/odp/utils"
pkgUtils "github.com/optimizely/go-sdk/pkg/utils"
Expand Down
3 changes: 2 additions & 1 deletion pkg/optimizelyjson/optimizely_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
package optimizelyjson

import (
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/goccy/go-json"
)

// OptimizelyJSON holds the underlying structure of the object
Expand Down
6 changes: 2 additions & 4 deletions pkg/utils/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"net/http"
"time"

"github.com/optimizely/go-sdk/pkg/logging"
"github.com/goccy/go-json"

jsoniter "github.com/json-iterator/go"
"github.com/optimizely/go-sdk/pkg/logging"
)

const (
Expand All @@ -47,8 +47,6 @@ const (
defaultTTL = 5 * time.Second
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

// Requester is used to make outbound requests with
type Requester interface {
Get(url string, headers ...Header) (response []byte, responseHeaders http.Header, code int, err error)
Expand Down
Loading