kickplan

package module
v0.0.0-...-a1afdaf Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 5 Imported by: 0

README

sdk-go

main

Installation

go get github.com/kickplan/sdk-go

Set environment variables:

export KICKPLAN_ENDPOINT=https://api...
export KICKPLAN_ACCESS_TOKEN=...

Usage

package main

import (
    "context"
    "log"

    kickplan "github.com/kickplan/sdk-go"
    "github.com/kickplan/sdk-go/adapter"
    "github.com/kickplan/sdk-go/eval"
)

func main() {
    ctx := context.Background()
    client := kickplan.NewClient()

    b, err := client.GetBool(ctx, "my-flag", false, eval.Context{
        "account_id": "123",
    })
    if err != nil {
        if errors.Is(err, adapter.ErrFlagNotFound) {
            log.Printf("flag %q not found", flag)
            return
        }
        log.Fatalf("failed to get flag: %v", err)
    }

    log.Printf("my-flag: %v", b)
}

See examples for more.

Documentation

Overview

Package kickplan provides a client to evaluate feature flags and work with metrics

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 Kickplan client.

func NewClient

func NewClient(opt ...Option) *Client

NewClient returns a new Kickplan client.

func (*Client) DecMetric

func (c *Client) DecMetric(
	ctx context.Context,
	metric string,
	value int64,
	evalCtx eval.Context,
) error

DecMetric decrements a metric.

func (*Client) GetBool

func (c *Client) GetBool(
	ctx context.Context,
	flag string,
	defaultValue bool,
	evalCtx eval.Context,
) (bool, error)

GetBool returns a boolean flag.

func (*Client) GetInt64

func (c *Client) GetInt64(
	ctx context.Context,
	flag string,
	defaultValue int64,
	evalCtx eval.Context,
) (int64, error)

GetInt64 returns a float64 flag.

func (*Client) GetObject

func (c *Client) GetObject(
	ctx context.Context,
	flag string,
	defaultValue interface{},
	evalCtx eval.Context,
) (interface{}, error)

GetObject returns a object flag.

func (*Client) GetString

func (c *Client) GetString(
	ctx context.Context,
	flag string,
	defaultValue string,
	evalCtx eval.Context,
) (string, error)

GetString returns a string flag.

func (*Client) IncMetric

func (c *Client) IncMetric(
	ctx context.Context,
	metric string,
	value int64,
	evalCtx eval.Context,
) error

IncMetric increments a metric.

func (*Client) SetBool

func (c *Client) SetBool(ctx context.Context, flag string, value bool) error

SetBool sets a boolean flag.

func (*Client) SetMetric

func (c *Client) SetMetric(
	ctx context.Context,
	metric string,
	value int64,
	evalCtx eval.Context,
) error

SetMetric sets a metric.

type Option

type Option func(*Client) error

Option is a function that configures a Client.

func WithAdapter

func WithAdapter(a adapter.Adapter) Option

WithAdapter sets the provider for the client.

Directories

Path Synopsis
Package adapter provides a way to work with flags and metrics
Package adapter provides a way to work with flags and metrics
Package eval provides the context for the evaluation of flags
Package eval provides the context for the evaluation of flags
examples
inmemory command
A simple example of using in-memory adapter
A simple example of using in-memory adapter
kickplan command
A simple example of using Kickplan adapter
A simple example of using Kickplan adapter

Jump to

Keyboard shortcuts

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