HappyKitClient

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 8 Imported by: 0

README

HappyKit Go Client (WIP)

Tests GoDoc codecov

A simple client library that interaces with the HappyKit feature flagging service

Install

$ go get github.com/gndimitro/happykit-go-client

Quick Start

// 1. Import the library
// 2. Initialize the client
// 3. Call isEnabled where needed

import (
	"fmt"

	happyKitClient "github.com/gndimitro/happykit-go-client"
)

func main() {
	happyKitClient.Initialize("flags_pub_development_XXXXXXX")

	if happyKitClient.IsEnabled("testFlag") {
		fmt.Println("Flag is enabled")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFlagValue added in v0.0.9

func GetFlagValue(featureFlagKey string, defaultValueOptional ...interface{}) interface{}

Fetches the flag value using the provided key

featureFlagKey (string) Key to be used when fetching the feature flag

defaultValueOptional (interface{}) Backup value to be used in case the feature flag isn't found in the current dataset, by default this is nil

func GetFlagValueForTraits added in v0.0.9

func GetFlagValueForTraits(featureFlagKey string, traits interface{}, defaultValueOptional ...interface{}) interface{}

Fetches the flag value using the provided feature flag key for the specified traits. Use when your flag value is of any other type supported by HappyKit. This function does not use a cache.

featureFlagKey (string) Key to be used when fetching the feature flag

defaultValueOptional (interface{}) Backup value to be used in case the feature flag isn't found in the current dataset, by default this is nil

func GetFlagValueForUser added in v0.0.9

func GetFlagValueForUser(featureFlagKey string, user User, defaultValueOptional ...interface{}) interface{}

Fetches the flag value using the provided key for the specified user. Use when your flag value is of any other type supported by HappyKit. This function does not use a cache.

featureFlagKey (string) Key to be used when fetching the feature flag

defaultValueOptional (interface{}) Backup value to be used in case the feature flag isn't found in the current dataset, by default this is nil

func Initialize added in v0.0.9

func Initialize(envKey string)

Initialze function to set and store the environment key for all future calls to HappyKit

func InitializeCustomCacheExpiry added in v0.0.9

func InitializeCustomCacheExpiry(envKey string, expirationTime time.Duration)

Initialze function to set and store the environment key for all future calls to HappyKit with a custom cache expiration time

func IsEnabled

func IsEnabled(featureFlagKey string, defaultValueOptional ...bool) bool

Returns the boolean value of the provided feature flag key

featureFlagKey (string) Key to be used when fetching the feature flag

defaultValueOptional (bool) Backup value to be used in case the feature flag isn't found in the current dataset

func IsEnabledForTraits added in v0.0.9

func IsEnabledForTraits(featureFlagKey string, traits interface{}, defaultValueOptional ...bool) bool

Checks if the flag is enabled for the specified traits. Use only when the flag expected is a boolean type

featureFlagKey (string) Key to be used when fetching the feature flag

user (User) User object to be used in the fetch

defaultValueOptional (bool) Backup value to be used in case the feature flag isn't found in the current dataset

func IsEnabledForUser added in v0.0.9

func IsEnabledForUser(featureFlagKey string, user User, defaultValueOptional ...bool) bool

Checks if the flag is enabled for a specified user. Use only when the flag expected is a boolean type

featureFlagKey (string) Key to be used when fetching the feature flag

user (User) User object to be used in the fetch

defaultValueOptional (bool) Backup value to be used in case the feature flag isn't found in the current dataset

Types

type FeatureFlags

type FeatureFlags map[string]interface{}

func FetchFeatureFlags

func FetchFeatureFlags() (FeatureFlags, bool)

Fetches the feature flags from the api without any extra paramaters

func FetchFeatureFlagsForTraits added in v0.0.9

func FetchFeatureFlagsForTraits(traits interface{}) (FeatureFlags, bool)

Fetches flags from the api using the provided traits

func FetchFeatureFlagsForUser added in v0.0.9

func FetchFeatureFlagsForUser(user User) (FeatureFlags, bool)

Fetches the feature flags from the api for the specified user

type RequestBody added in v0.0.9

type RequestBody struct {
	User    User        `json:"user,omitempty"`
	Visitor Visitor     `json:"visitorKey,omitempty"`
	Traits  interface{} `json:"traits,omitempty"`
}

Request body to be sent to HappyKit for complex flag requests

type RequestResponseBody

type RequestResponseBody struct {
	Flags FeatureFlags
}

type User added in v0.0.9

type User struct {
	Key     string `json:"key"`
	Email   string `json:"email,omitempty"`
	Name    string `json:"name,omitempty"`
	Avatar  string `json:"avatar,omitempty"`
	Country string `json:"country,omitempty"`
}

A user struct used to pass to the API

key (string) (required): Unique key for this user

email (string): Email-Address

name (string): Full name or nickname

avatar (string): URL to users profile picture

country (string): Two-letter uppercase country-code, see ISO 3166-1

type Visitor added in v0.0.9

type Visitor struct {
	Key string `json:"key"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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