Skip to content

Commit

Permalink
docs(golang-sdk): Update go sdk docs (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi authored Oct 30, 2023
1 parent 78e559c commit 2c6096d
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions docs/docs/clients/server-side.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,11 @@ $flagsmith = new Flagsmith('<FLAGSMITH_SERVER_SIDE_ENVIRONMENT_KEY>');

```go
import (
flagsmith "github.com/Flagsmith/flagsmith-go-client"
"os"
flagsmith "github.com/Flagsmith/flagsmith-go-client/v3"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Initialise the Flagsmith client
client := flagsmith.NewClient('<FLAGSMITH_SERVER_SIDE_ENVIRONMENT_KEY>', flagsmith.WithContext(ctx),)
client := flagsmith.NewClient(os.Getenv("FLAGSMITH_ENVIRONMENT_KEY"))
```

</TabItem>
Expand Down Expand Up @@ -387,7 +385,7 @@ $flags->getFeatureValue('secret_button');

```go
// The method below triggers a network request
flags, _ := client.GetEnvironmentFlags()
flags, _ := client.GetEnvironmentFlags(ctx)
showButton, _ := flags.IsFeatureEnabled("secret_button")
buttonData, _ := flags.GetFeatureValue("secret_button")
```
Expand Down Expand Up @@ -517,7 +515,7 @@ trait := flagsmith.Trait{TraitKey: "trait", TraitValue: "trait_value"}
traits = []*flagsmith.Trait{&trait}

// The method below triggers a network request
flags, _ := client.GetIdentityFlags(identifier, traits)
flags, _ := client.GetIdentityFlags(ctx, identifier, traits)

showButton, _ := flags.IsFeatureEnabled("secret_button")
buttonData, _ := flags.GetFeatureValue("secret_button")
Expand Down Expand Up @@ -689,12 +687,17 @@ $flagsmith = (new Flagsmith('<FLAGSMITH_SERVER_SIDE_ENVIRONMENT_KEY>'))
<TabItem value="go" label="Go">

```go
func defaultFlagHandler(featureName string) flagsmith.Flag {
return flagsmith.Flag{IsDefault: true, FeatureName: featureName, Value: `{"colour": "#ababab"}`}
func DefaultFlagHandler(featureName string) (flagsmith.Flag, error) {
return flagsmith.Flag{
FeatureName: featureName,
IsDefault: true,
Value: `{"colour": "#FFFF00"}`,
Enabled: true,
}, nil
}

client := flagsmith.NewClient(os.Getenv("FLAGSMITH_API_KEY"),
flagsmith.WithDefaultHandler(defaultFlagHandler),
flagsmith.WithDefaultHandler(DefaultFlagHandler),
)

```
Expand Down Expand Up @@ -1239,7 +1242,7 @@ client := flagsmith.NewClient(os.Getenv("FLAGSMITH_API_KEY"),
// Controls which mode to run in; local or remote evaluation.
// See the `SDKs Overview Page` for more info
// Defaults to False
flagsmith.WithLocalEvaluation(),
func WithLocalEvaluation(ctx context.Context),

// The network timeout in seconds.
flagsmith.WithRequestTimeout(10*time.Second),
Expand All @@ -1251,7 +1254,7 @@ client := flagsmith.NewClient(os.Getenv("FLAGSMITH_API_KEY"),

// Controls whether Flag Analytics data is sent to the Flagsmith API
// See https://docs.flagsmith.com/advanced-use/flag-analytics
flagsmith.WithAnalytics(),
flagsmith.WithAnalytics(ctx),

// Sets `resty.Client` options. `SetRetryCount` and `SetRetryWaitTime`
// Ref: https://pkg.go.dev/github.com/go-resty/resty/v2#Client.SetRetryCount
Expand All @@ -1270,8 +1273,16 @@ client := flagsmith.NewClient(os.Getenv("FLAGSMITH_API_KEY"),
// response
flagsmith.WithDefaultHandler(defaultFlagHandler),

// You can specify the context to use.
flagsmith.WithContext(ctx),
// Allows the client to use any logger that implements the `Logger` interface.
flagsmith.WithLogger(ctx),

// WithProxy returns an Option function that sets the proxy(to be used by internal resty client).
// The proxyURL argument is a string representing the URL of the proxy server to use, e.g. "http://proxy.example.com:8080".
func WithProxy(proxyURL string) Option {
return func(c *Client) {
c.client.SetProxy(proxyURL)
}
}
)
```

Expand Down

3 comments on commit 2c6096d

@vercel
Copy link

@vercel vercel bot commented on 2c6096d Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-flagsmith.vercel.app
docs-git-main-flagsmith.vercel.app
docs.flagsmith.com
docs.bullet-train.io

@vercel
Copy link

@vercel vercel bot commented on 2c6096d Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 2c6096d Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.