Skip to content

Commit

Permalink
feat: Add SDK id and version to requests (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria authored Nov 15, 2023
1 parent 6f0451d commit b63d8f7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ Before starting to use the provider, it can be helpful to read through the gener
and get familiar with the concepts.

## Adding the dependency
<!---x-release-please-start-version-->
```
require (
github.com/spotify/confidence-openfeature-provider-go v0.1.4
github.com/open-feature/go-sdk v1.7.0
)
```
<!---x-release-please-end-->

### Creating and using the flag provider

Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ type resolveRequest struct {
Apply bool `json:"apply"`
EvaluationContext map[string]interface{} `json:"evaluation_context"`
Flags []string `json:"flags"`
Sdk sdk `json:"sdk"`
}

type sdk struct {
Id string `json:"id"`
Version string `json:"version"`
}

type resolveResponse struct {
Expand Down
8 changes: 7 additions & 1 deletion pkg/provider/provider.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type FlagProvider struct {
ResolveClient resolveClient
}

var (
SDK_ID = "SDK_ID_GO_PROVIDER"
SDK_VERSION = "0.1.4" // x-release-please-version
)

func NewFlagProvider(config APIConfig) (*FlagProvider, error) {
validationError := config.validate()
if validationError != nil {
Expand Down Expand Up @@ -64,7 +69,8 @@ func (e FlagProvider) resolveFlag(ctx context.Context, flag string, defaultValue
requestFlagName := fmt.Sprintf("flags/%s", flagName)
resp, err := e.ResolveClient.sendResolveRequest(ctx,
resolveRequest{ClientSecret: e.Config.APIKey,
Flags: []string{requestFlagName}, Apply: true, EvaluationContext: evalCtx})
Flags: []string{requestFlagName}, Apply: true, EvaluationContext: evalCtx,
Sdk: sdk{Id: SDK_ID, Version: SDK_VERSION}})

if err != nil {
return processResolveError(err, defaultValue)
Expand Down
5 changes: 4 additions & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"prerelease": false,
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"extra-files": ["README.md"],
"extra-files": [
"README.md",
"pkg/provider/provider.go"
],
"changelog-sections": [
{
"type": "fix",
Expand Down

0 comments on commit b63d8f7

Please sign in to comment.