Skip to content

Commit

Permalink
chore: Bump major version, add evaluation context codegen to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Oct 21, 2024
1 parent ec6639a commit 7d6ca0a
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
with:
submodules: recursive

- name: Build evaluation context struct
run: make generate-evaluation-context

- name: Get dependencies
run: |
go get -v -t -d ./...
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ EVALUATION_CONTEXT_SCHEMA_URL ?= https://raw.githubusercontent.com/Flagsmith/fla

.PHONY: generate-evaluation-context
generate-evaluation-context:
npx quicktype ${EVALUATION_CONTEXT_SCHEMA_URL} --src-lang schema --lang go --package flagsmith --omit-empty --just-types-and-package > evaluationcontext.go
npx quicktype ${EVALUATION_CONTEXT_SCHEMA_URL} \
--src-lang schema \
--lang go \
--package flagsmith \
--omit-empty \
--just-types-and-package \
> evaluationcontext.go
14 changes: 7 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"sync/atomic"
"time"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
"github.com/go-resty/resty/v2"

enginetraits "github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
enginetraits "github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
)

type contextKey string
Expand Down Expand Up @@ -117,7 +117,7 @@ func (c *Client) GetFlags(ctx context.Context, ec *EvaluationContext) (f Flags,
if ec != nil {
ctx = WithEvaluationContext(ctx, *ec)
if ec.Identity != nil {
return c.GetIdentityFlags(ctx, ec.Identity.Identifier, mapIdentityEvaluationContextToTraits(*ec.Identity))
return c.GetIdentityFlags(ctx, *ec.Identity.Identifier, mapIdentityEvaluationContextToTraits(*ec.Identity))
}
}
return c.GetEnvironmentFlags(ctx)
Expand Down Expand Up @@ -263,7 +263,7 @@ func (c *Client) GetIdentityFlagsFromAPI(ctx context.Context, identifier string,
idCtx := ec.Identity
if idCtx != nil {
// `Identifier` and `Traits` had been set by `GetFlags` earlier.
body.Transient = &idCtx.Transient
body.Transient = idCtx.Transient
}
}
resp, err := req.
Expand Down
17 changes: 11 additions & 6 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"testing"
"time"

flagsmith "github.com/Flagsmith/flagsmith-go-client/v3"
"github.com/Flagsmith/flagsmith-go-client/v3/fixtures"
flagsmith "github.com/Flagsmith/flagsmith-go-client/v4"

Check failure on line 14 in client_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

could not import github.com/Flagsmith/flagsmith-go-client/v4 (-: # github.com/Flagsmith/flagsmith-go-client/v4 [github.com/Flagsmith/flagsmith-go-client/v4.test]
"github.com/Flagsmith/flagsmith-go-client/v4/fixtures"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -204,6 +204,8 @@ func TestGetFlags(t *testing.T) {

func TestGetFlagsTransientIdentity(t *testing.T) {
// Given
identifier := "transient"
transient := true
ctx := context.Background()
expectedRequestBody := `{"identifier":"transient","transient":true}`
server := getTestHttpServer(t, "/api/v1/identities/", fixtures.EnvironmentAPIKey, &expectedRequestBody, fixtures.IdentityResponseJson)
Expand All @@ -212,7 +214,7 @@ func TestGetFlagsTransientIdentity(t *testing.T) {
// When
client := flagsmith.NewClient(fixtures.EnvironmentAPIKey, flagsmith.WithBaseURL(server.URL+"/api/v1/"))

flags, err := client.GetFlags(ctx, &flagsmith.EvaluationContext{Identity: &flagsmith.IdentityEvaluationContext{Identifier: "transient", Transient: true}})
flags, err := client.GetFlags(ctx, &flagsmith.EvaluationContext{Identity: &flagsmith.IdentityEvaluationContext{Identifier: &identifier, Transient: &transient}})

// Then
assert.NoError(t, err)
Expand All @@ -228,6 +230,8 @@ func TestGetFlagsTransientIdentity(t *testing.T) {

func TestGetFlagsTransientTraits(t *testing.T) {
// Given
identifier := "test_identity"
transient := true
ctx := context.Background()
expectedRequestBody := `{"identifier":"test_identity","traits":` +
`[{"trait_key":"NullTrait","trait_value":null},` +
Expand All @@ -243,13 +247,13 @@ func TestGetFlagsTransientTraits(t *testing.T) {
ctx,
&flagsmith.EvaluationContext{
Identity: &flagsmith.IdentityEvaluationContext{
Identifier: "test_identity",
Identifier: &identifier,
Traits: map[string]*flagsmith.TraitEvaluationContext{
"NullTrait": nil,
"StringTrait": {Value: "value"},
"TransientTrait": {
Value: "value",
Transient: true,
Transient: &transient,
},
},
},
Expand Down Expand Up @@ -289,6 +293,7 @@ func TestGetFlagsEnvironmentEvaluationContextFlags(t *testing.T) {

func TestGetFlagsEnvironmentEvaluationContextIdentity(t *testing.T) {
// Given
identifier := "test_identity"
ctx := context.Background()
expectedEnvKey := "different"
server := getTestHttpServer(t, "/api/v1/identities/", expectedEnvKey, nil, fixtures.IdentityResponseJson)
Expand All @@ -301,7 +306,7 @@ func TestGetFlagsEnvironmentEvaluationContextIdentity(t *testing.T) {
ctx,
&flagsmith.EvaluationContext{
Environment: &flagsmith.EnvironmentEvaluationContext{APIKey: expectedEnvKey},
Identity: &flagsmith.IdentityEvaluationContext{Identifier: "test_identity"},
Identity: &flagsmith.IdentityEvaluationContext{Identifier: &identifier},
})

// Then
Expand Down
6 changes: 3 additions & 3 deletions evaluationcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type FeatureEvaluationContext struct {
}

type IdentityEvaluationContext struct {
Identifier string `json:"identifier,omitempty"`
Identifier *string `json:"identifier,omitempty"`
Traits map[string]*TraitEvaluationContext `json:"traits,omitempty"`
Transient bool `json:"transient,omitempty"`
Transient *bool `json:"transient,omitempty"`
}

type TraitEvaluationContext struct {
Transient bool `json:"transient,omitempty"`
Transient *bool `json:"transient,omitempty"`
Value interface{} `json:"value"`
}
5 changes: 3 additions & 2 deletions evaluationcontext_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ func NewEvaluationContext(identifier string, traits map[string]interface{}) Eval
traitsCtx[tKey] = &tCtx
}
ec.Identity = &IdentityEvaluationContext{
Identifier: identifier,
Identifier: &identifier,
Traits: traitsCtx,
}
return ec
}

func NewTransientEvaluationContext(identifier string, traits map[string]interface{}) EvaluationContext {
ec := NewEvaluationContext(identifier, traits)
ec.Identity.Transient = true
var transient = true
ec.Identity.Transient = &transient
return ec
}
10 changes: 5 additions & 5 deletions flagengine/engine.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package flagengine

import (
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
)

// GetEnvironmentFeatureStates returns a list of feature states for a given environment.
Expand Down
10 changes: 5 additions & 5 deletions flagengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package flagengine_test
import (
"testing"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils/fixtures"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils/fixtures"
"github.com/stretchr/testify/assert"
)

Expand Down
6 changes: 3 additions & 3 deletions flagengine/environments/models.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package environments

import (
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/projects"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/projects"
)

type EnvironmentModel struct {
Expand Down
2 changes: 1 addition & 1 deletion flagengine/features/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sort"
"strconv"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

type FeatureModel struct {
Expand Down
2 changes: 1 addition & 1 deletion flagengine/features/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package features_test
import (
"testing"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/stretchr/testify/assert"
)

Expand Down
10 changes: 5 additions & 5 deletions flagengine/flagengine_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
)

const TestData = "./engine-test-data/data/environment_n9fbf9h3v4fFgH3U3ngWhb.json"
Expand Down
6 changes: 3 additions & 3 deletions flagengine/identities/models.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package identities

import (
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

type IdentityModel struct {
Expand Down
4 changes: 2 additions & 2 deletions flagengine/projects/models.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package projects

import (
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/organisations"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/organisations"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
)

type ProjectModel struct {
Expand Down
6 changes: 3 additions & 3 deletions flagengine/segments/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"strconv"
"strings"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
"github.com/blang/semver/v4"
"golang.org/x/exp/slices"
)
Expand Down
10 changes: 5 additions & 5 deletions flagengine/segments/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

"github.com/stretchr/testify/assert"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils/fixtures"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils/fixtures"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions flagengine/segments/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strconv"
"strings"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

type SegmentConditionModel struct {
Expand Down
16 changes: 8 additions & 8 deletions flagengine/utils/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package fixtures
import (
"time"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/organisations"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/projects"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/organisations"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/projects"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/segments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion flagengine/utils/hashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/assert"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

func TestGetHashedPercentageForObjectIds(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion flagengine/utils/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/utils"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/utils"
)

func TestUnmarshal(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/Flagsmith/flagsmith-go-client/v3
module github.com/Flagsmith/flagsmith-go-client/v4

go 1.22

Expand All @@ -16,6 +16,7 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/elastic/go-json-schema-generate v0.0.0-20220519132038-c708d18d6ca2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.27.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
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/elastic/go-json-schema-generate v0.0.0-20220519132038-c708d18d6ca2 h1:C8FTj5Y0BfGNSFyQI6V0HeATwKwTlLfU8qletYG7V8Y=
github.com/elastic/go-json-schema-generate v0.0.0-20220519132038-c708d18d6ca2/go.mod h1:w6t176CDaF2cZXwuQtFA5T+trYjvo5OYxLbBwAE7gxU=
github.com/go-resty/resty/v2 v2.14.0 h1:/rhkzsAqGQkozwfKS5aFAbb6TyKd3zyFRWcdRXLPCAU=
github.com/go-resty/resty/v2 v2.14.0/go.mod h1:IW6mekUOsElt9C7oWr0XRt9BNSD6D5rr9mhk6NjmNHg=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
Expand Down
4 changes: 2 additions & 2 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"encoding/json"
"fmt"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/features"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/features"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/identities/traits"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/identities/traits"
)

type Flag struct {
Expand Down
2 changes: 1 addition & 1 deletion offline_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"os"

"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
)

type OfflineHandler interface {
Expand Down
Loading

0 comments on commit 7d6ca0a

Please sign in to comment.