Skip to content

Commit

Permalink
docs: improve onboarding (#150)
Browse files Browse the repository at this point in the history
* docs: improve onboarding

When getting started with go sdk it's easy to miss waiting for initialization. This change will make it easy for newcomers to use the SDK and more advanced users should be able to wait for the readiness in different ways if they don't want to block the main thread

* Add two initialization options

* Fail fast on timeout
  • Loading branch information
gastonfournier authored Nov 21, 2023
1 parent 07d99cb commit 5b4ae18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- name: Go vet
run: go vet ./...
- name: Run all tests
timeout-minutes: 1
run: go test -race -covermode atomic -coverprofile=profile.cov -v ./...
- name: Send coverage
uses: shogo82148/actions-goveralls@v1
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ go get github.com/Unleash/unleash-client-go

The easiest way to get started with Unleash is to initialize it early in your application code:

**Asynchronous initialization example:**
```go
import (
"github.com/Unleash/unleash-client-go/v4"
Expand All @@ -49,6 +50,26 @@ func init() {
}
```

**Synchronous initialization example:**

```go
import (
"github.com/Unleash/unleash-client-go/v4"
)

func init() {
unleash.Initialize(
unleash.WithListener(&unleash.DebugListener{}),
unleash.WithAppName("my-application"),
unleash.WithUrl("http://unleash.herokuapp.com/api/"),
unleash.WithCustomHeaders(http.Header{"Authorization": {"<API token>"}}),
)

// Note this will block until the default client is ready
unleash.WaitForReady()
}
```

#### Preloading feature toggles

If you'd like to prebake your application with feature toggles (maybe you're working without persistent storage, so Unleash's backup isn't available), you can replace the defaultStorage implementation with a BootstrapStorage. This allows you to pass in a reader to where data in the format of `/api/client/features` can be found.
Expand Down

0 comments on commit 5b4ae18

Please sign in to comment.