rocketflag

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 4 Imported by: 0

README

RocketFlag Go SDK

This SDK provides a convenient way to interact with the RocketFlag API from your Go applications.

Installation

go get github.com/rocketflag/go-sdk

Basic Usage

package main

import (
	"context"
	"fmt"
	"log"

	rocketflag "github.com/rocketflag/go-sdk"
)

func main() {
	rf := rocketflag.NewClient()

	// Example: Get a single flag
	flag, err := rf.GetFlag("flag-id", rocketflag.UserContext{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Flag:", flag)
}

Including a Cohort

If you want to use a cohort and only enable flags for certain users, you'll need to setup the accepted cohorts in the console. Once done, you can pass the cohort like so with the SDK:

flag, err := rf.GetFlag("flag-id", rocketflag.UserContext{"cohort": "user@example.com"})

Overrides

HTTP Client

You can pass in http clients if you use them or have custom ones. Eg:

import (
	"net/http"
)

customHttpClient := &http.Client{}

client := rocketflag.NewClient(WithHTTPClient(customHttpClient))
Custom version

By default, RocketFlag will use the latest API version that the SDK knows about. Right now, this is version 1. You can override this if you prefer as so:

client := rocketflag.NewClient(WithVersion("v2"))
Custom URL

By default, RocketFlag will use the RocketFlag API. This is https://api.rocketflag.app. You can override this if you prefer as so:

client := rocketflag.NewClient(WithAPIURL("https://api.example.com"))
Chaining custom client options
client := rocketflag.NewClient(
  WithHTTPClient(customHttpClient),
  WithVersion("v2"),
  WithAPIURL("https://api.example.com")
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a RocketFlag API client.

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new Client with optional configurations.

func (*Client) GetFlag

func (c *Client) GetFlag(flagID string, userContext UserContext) (*FlagStatus, error)

GetFlag retrieves a feature flag from the RocketFlag API.

type ClientOption

type ClientOption func(*Client)

ClientOption defines a function type that modifies the Client.

func WithAPIURL

func WithAPIURL(apiUrl string) ClientOption

WithAPIURL sets the API URL for the Client.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient sets a custom HTTP client for the Client.

func WithVersion

func WithVersion(version string) ClientOption

WithVersion sets the version for the Client.

type FlagStatus

type FlagStatus struct {
	Name    string `json:"name"`
	Enabled bool   `json:"enabled"`
	ID      string `json:"id"`
}

FlagStatus represents the status of a feature flag.

type UserContext

type UserContext map[string]interface{}

UserContext allows for passing user-specific context to the API, such as a cohort.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL