https://github.com/devcyclehq/go-server-sdk
DevCycle - Go Server SDK
https://github.com/devcyclehq/go-server-sdk
continuous-delivery continuous-deployment devcycle devops feature-flags feature-toggles openfeature
Last synced: about 1 month ago
JSON representation
DevCycle - Go Server SDK
- Host: GitHub
- URL: https://github.com/devcyclehq/go-server-sdk
- Owner: DevCycleHQ
- License: mit
- Created: 2021-11-24T19:35:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-19T14:46:01.000Z (about 1 month ago)
- Last Synced: 2025-03-19T15:30:00.549Z (about 1 month ago)
- Topics: continuous-delivery, continuous-deployment, devcycle, devops, feature-flags, feature-toggles, openfeature
- Language: Go
- Homepage: https://docs.devcycle.com/
- Size: 19.8 MB
- Stars: 19
- Watchers: 8
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DevCycle Go Server SDK.
This SDK supports both cloud bucketing (requests outbound to https://bucketing-api.devcycle.com) as well as local bucketing (requests to a local bucketing engine self-contained in this SDK).
## Installation
```bash
go get "github.com/devcyclehq/go-server-sdk/v2"
``````golang
package main
import "github.com/devcyclehq/go-server-sdk/v2"
```## Getting Started
```golang
sdkKey := os.Getenv("DEVCYCLE_SERVER_SDK_KEY")
user := devcycle.User{UserId: "test"}options := devcycle.Options{
EnableEdgeDB: false,
EnableCloudBucketing: false,
EventFlushIntervalMS: 0,
ConfigPollingIntervalMS: 10 * time.Second,
RequestTimeout: 10 * time.Second,
DisableAutomaticEventLogging: false,
DisableCustomEventLogging: false,
}client, _ := devcycle.NewClient(sdkKey, &options)
```## Usage
To find usage documentation, visit our [docs](https://docs.devcycle.com/docs/sdk/server-side-sdks/go#usage).
## Testing
This SDK is supported by our [test harness](https://github.com/DevCycleHQ/test-harness), a test suite shared between all DevCycle SDKs for consistency.
Unit tests can be run with the standard Go testing tools, or with `make test`. They are run automatically on PRs with the [Go race detector](https://go.dev/doc/articles/race_detector) enabled. To reproduce this locally, run with `RACE=1 make test`. Some race detector errors might only show up on Github actions due to differences in how quickly tests are executed.
## Configuration
Configuration of the SDK is done through the `Options` struct.
## Logging
By default, logging is disabled to avoid overhead and noise in your logs. To enable it for debugging the SDK, set the `devcycle_debug_logging` build tag when compiling your project:
```
go build -tags devcycle_debug_logging ...
```### Cloud Bucketing
The following options are available when you are using the SDK in Cloud Bucketing mode.
| Option | Type | Description | Default |
| --- |---------------|-------------------------------------------------------------------------------------------------------------------------------------------|---------|
| EnableCloudBucketing | bool | Sets the SDK to Cloud Bucketing mode | false |
| EnableEdgeDB | bool | Turns on EdgeDB support for Cloud Bucketing | false |
| BucketingAPIURI | string | The base URI for communicating with the DevCycle Cloud Bucketing service. Can be set if you need to proxy traffic through your own server | https://bucketing-api.devcycle.com |
| Logger | util.Logger | Allows you to set a custom logger to manage output from the SDK. The default logger will write to stdout and stderr | nil |### Local Bucketing
The following options are available when you are using the SDK in Local Bucketing mode.
| Option | Type | Description | Default |
|------------------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|
| OnInitializedChannel | chan bool | A callback channel to get notified when the SDK is fully initialized and ready to use | nil |
| EventFlushIntervalMS | time.Duration | How frequently events are flushed to the backend.
*value must be between 500ms and 60s* | 30000 |
| ConfigPollingIntervalMS | time.Duration | How frequently the SDK will attempt to reload the feature config.
*value must be > 1s* | 10000 |
| RequestTimeout | time.Duration | Maximum time to spend retrieving project configurations.
*value must be > 5s* | 5000 |
| DisableAutomaticEventLogging | bool | Turn off tracking of automated variable events | false |
| DisableCustomEventLogging | bool | Turns off tracking of custom events submitted via the client.Track() | false |
| MaxEventQueueSize | int | Maximum size of the event queue before new events get dropped. Higher values can impact memory usage of the SDK.
*value must be > 0 and <= 50000.* | 10000 |
| FlushEventQueueSize | int | Maximum size of the queue used to prepare events for submission to DevCycle. Higher values can impact memory usage of the SDK.
*value must be > 0 and <= 50000.* | 1000 | |
| ConfigCDNURI | string | The base URI for retrieving your project configuration from DevCycle. Can be set if you need to proxy traffic through your own server | https://config-cdn.devcycle.com |
| EventsAPIURI | string | The base URI for sending events to DevCycle for analytics tracking. Can be set if you need to proxy traffic through your own server | https://events.devcycle.com |
| Logger | util.Logger | Allows you to set a custom logger to manage output from the SDK. The default logger will write to stdout and stderr | nil |
# OpenFeature SupportThis SDK provides an implementation of the [OpenFeature](https://openfeature.dev/) Provider interface. Use the `OpenFeatureProvider()` method on the DevCycle SDK client to obtain a provider for OpenFeature.
```go
devcycleClient, err := devcycle.NewClient("DEVCYCLE_SERVER_SDK_KEY", &options)
err = openfeature.SetProvider(devcycleClient.OpenFeatureProvider())
```- [The DevCycle Go OpenFeature Provider](https://docs.devcycle.com/sdk/server-side-sdks/go/go-openfeature)
- [The OpenFeature documentation](https://openfeature.dev/docs/reference/intro)## Linting
We run golangci/golangci-lint on every PR to catch common errors. You can run the linter locally via the Makefile with:
```
make lint
```Lint failures on PRs will show comments on the "Files changed" tab inline with the code, not on the main Conversation tab.