Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/sdk-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:
jobs:
sdk-spec:
# Keep the ref in `uses:` and `spec-ref` in sync.
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.3.0
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.6.0
with:
spec-ref: v0.3.0
spec-ref: v0.6.0
language: go
25 changes: 25 additions & 0 deletions sdk-spec/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ func CreateClient(environmentKey, apiURL string) *flagsmith.Client {
return flagsmith.NewClient(environmentKey, flagsmith.WithBaseURL(apiURL))
}

// Create the SDK client with events enabled
func CreateClientWithEvents(environmentKey, apiURL, eventsURL string) *flagsmith.Client {
return flagsmith.NewClient(environmentKey,
flagsmith.WithBaseURL(apiURL),
flagsmith.WithEvents(context.Background()),
flagsmith.WithEventsBaseURL(eventsURL),
)
}

// When the application gets the environment flags
func GetEnvironmentFlags(client *flagsmith.Client) ([]Flag, error) {
flags, err := client.GetEnvironmentFlags(context.Background())
Expand All @@ -43,3 +52,19 @@ func GetIdentityFlags(client *flagsmith.Client, identifier string, traits map[st
flags, err := client.GetIdentityFlags(context.Background(), identifier, sdkTraits)
return asSpecFlags(flags), err
}

// When the application gets the experiment flag "{feature}" for identity "{identifier}" with traits:
func GetExperimentFlag(client *flagsmith.Client, feature, identifier string, traits map[string]any) ([]Flag, error) {
flag, err := client.GetExperimentFlag(context.Background(), feature, flagsmith.NewEvaluationContext(identifier, traits))
return []Flag{{Feature: flag.FeatureName, Enabled: flag.Enabled, Value: flag.Value}}, err
}

// When the application tracks event "{event}" for identity "{identifier}" with value {value} and metadata:
func TrackEvent(client *flagsmith.Client, event, identifier string, value any, metadata map[string]any) error {
return client.TrackEvent(event, &flagsmith.EventOptions{Identifier: identifier, Value: value, Metadata: metadata})
}

// When the application tracks an exposure of feature "{feature}" for identity "{identifier}" with value {value} and metadata:
func TrackExposureEvent(client *flagsmith.Client, feature, identifier string, value any, metadata map[string]any) error {
return client.TrackExposureEvent(feature, identifier, value, &flagsmith.EventOptions{Metadata: metadata})
}
Loading