models

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultScope = "default"

DefaultScope the key in which default features are set. By default `dcdr/features/<DefaultScope>`/<feature-name>.

Variables

This section is empty.

Functions

This section is empty.

Types

type Feature

type Feature struct {
	FeatureType FeatureType `json:"feature_type"`
	Key         string      `json:"key"`
	Namespace   string      `json:"namespace"`
	Scope       string      `json:"scope"`
	Value       interface{} `json:"value"`
	Comment     string      `json:"comment"`
	UpdatedBy   string      `json:"updated_by"`
}

Feature KV model for feature flags

func NewFeature

func NewFeature(name string, value interface{}, comment string, user string, scope string, ns string) (f *Feature)

NewFeature create a Feature

func (*Feature) BoolValue

func (f *Feature) BoolValue() bool

BoolValue cast Value to bool

func (*Feature) FloatValue

func (f *Feature) FloatValue() float64

FloatValue cast Value to float64

func (*Feature) GetNamespace

func (f *Feature) GetNamespace() string

GetNamespace formats the fully scoped namespace

func (*Feature) GetScope

func (f *Feature) GetScope() string

GetScope scope accessor

func (*Feature) ScopedKey

func (f *Feature) ScopedKey() string

ScopedKey expanded key with namespace and scope

func (*Feature) ToJSON

func (f *Feature) ToJSON() ([]byte, error)

ToJSON marshal feature to json

type FeatureMap

type FeatureMap struct {
	Dcdr Root `json:"dcdr"`
}

FeatureMap contains a nested map of `Features` and `Info`.

func EmptyFeatureMap

func EmptyFeatureMap() (fm *FeatureMap)

EmptyFeatureMap helper method for constructing an empty `FeatureMap`.

func NewFeatureMap

func NewFeatureMap(bts []byte) (*FeatureMap, error)

NewFeatureMap constructs a `FeatureMap` for marshalled JSON.

func (*FeatureMap) ToJSON

func (fm *FeatureMap) ToJSON() ([]byte, error)

ToJSON helper method for marshalling a `FeatureMap` to JSON.

type FeatureScopes

type FeatureScopes map[string]interface{}

FeatureScopes the map of percentile and boolean K/Vs.

type FeatureType

type FeatureType string

FeatureType accepted feature types

const (
	// Percentile percentile `FeatureType`
	Percentile FeatureType = "percentile"
	// Boolean boolean `FeatureType`
	Boolean FeatureType = "boolean"
	// Invalid invalid `FeatureType`
	Invalid FeatureType = "invalid"
	// FeatureScope scoping for feature keys
	FeatureScope = "features"
)

func ParseValueAndFeatureType

func ParseValueAndFeatureType(v string) (interface{}, FeatureType)

ParseValueAndFeatureType string to type helper

type Features

type Features []Feature

Features a Feature result set

func (Features) Len

func (a Features) Len() int

func (Features) Less

func (a Features) Less(i, j int) bool

func (Features) Swap

func (a Features) Swap(i, j int)

type Info

type Info struct {
	CurrentSHA       string `json:"current_sha,omitempty"`
	LastModifiedDate int64  `json:"last_modfied_date,omitempty"`
}

Info contains the metadata for the current `FeatureMap`.

type Root

type Root struct {
	sync.RWMutex
	Info          *Info         `json:"info"`
	FeatureScopes FeatureScopes `json:"features"`
}

Root wrapper struct for `Info` and `Features`.

func (*Root) CurrentSHA

func (d *Root) CurrentSHA() string

CurrentSHA accessor for the underlying `CurrentSHA` found in `Info`.

func (*Root) Defaults

func (d *Root) Defaults() FeatureScopes

Defaults returns `Features` within the 'default' scope.

func (*Root) InScope

func (d *Root) InScope(scope string) FeatureScopes

InScope returns the `Features` found within `scope`.

func (*Root) MergedScopes

func (d *Root) MergedScopes(scopes ...string) FeatureScopes

MergedScopes given a slice of scopes in priority order will return a merged set of `Featured` including the 'default' scope.

Jump to

Keyboard shortcuts

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