realm

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPollingInterval is used as the default polling interval for realm
	DefaultPollingInterval time.Duration = 15 * time.Minute
)

Variables

View Source
var (
	ErrChamberEmpty = errors.New("chamber is nil")
)
View Source
var (
	// RequestContextKey is the context key to use with a WithValue function to associate a root chamber value with a context
	// such that rule retrievals will be consistent throughout the client's request
	RequestContextKey = &contextKey{"realm"}
)

Functions

This section is empty.

Types

type Chamber

type Chamber struct {
	Rules map[string]*OverrideableRule `json:"rules"`
}

Chamber is a struct that holds metadata and rules

func (*Chamber) InheritFrom added in v0.2.0

func (c *Chamber) InheritFrom(from *Chamber)

InheritFrom inherits rules from the provided chamber if they do not exist in the current chamber

func (*Chamber) OverwriteFrom added in v0.2.0

func (c *Chamber) OverwriteFrom(overwrittenFrom *Chamber)

OverwriteFrom overwrites rules from the provided chamber

func (*Chamber) UnmarshalJSON

func (c *Chamber) UnmarshalJSON(b []byte) error

type ChamberEntry added in v0.0.18

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

ChamberEntry is a read-only version of Chamber it is specifically used for realm clients

func NewChamberEntry added in v0.0.18

func NewChamberEntry(c *Chamber, version string) *ChamberEntry

NewChamberEntry creates a new ChamberEntry with the specified version

func (*ChamberEntry) BoolValue added in v0.0.18

func (c *ChamberEntry) BoolValue(ruleKey string, defaultValue bool) (bool, error)

BoolValue retrieves a bool by the key of the rule and returns the default value if it does not exist and an error if it is not found or could not be converted

func (*ChamberEntry) CustomValue added in v0.0.18

func (c *ChamberEntry) CustomValue(ruleKey string, v any) error

CustomValue retrieves a json.RawMessage by the key of the rule and returns an error if it is not found or could not be converted

func (*ChamberEntry) Float64Value added in v0.0.18

func (c *ChamberEntry) Float64Value(ruleKey string, defaultValue float64) (float64, error)

Float64Value retrieves a float64 by the key of the rule and returns the default value if it does not exist and an error if it is not found or could not be converted

func (*ChamberEntry) Get added in v0.0.18

func (c *ChamberEntry) Get(ruleKey string) *OverrideableRule

Get returns the rule with the specified ruleKey. Will return nil if the rule does not exist

func (*ChamberEntry) StringValue added in v0.0.18

func (c *ChamberEntry) StringValue(ruleKey string, defaultValue string) (string, error)

StringValue retrieves a string by the key of the rule and returns the default value if it does not exist and an error if it is not found or could not be converted

type ErrCouldNotConvertRule added in v0.0.24

type ErrCouldNotConvertRule struct {
	Key  string
	Type string
}

func (*ErrCouldNotConvertRule) Error added in v0.0.24

func (cnc *ErrCouldNotConvertRule) Error() string

type ErrRuleNotFound added in v0.0.24

type ErrRuleNotFound struct {
	Key string
}

func (*ErrRuleNotFound) Error added in v0.0.24

func (tnf *ErrRuleNotFound) Error() string

type Override

type Override struct {
	*Rule
	MinimumVersion string `json:"minimumVersion"`
	MaximumVersion string `json:"maximumVersion"`
}

Override is a rule value to be consumed by and restricted to a semantic version range

func (*Override) UnmarshalJSON

func (o *Override) UnmarshalJSON(b []byte) error

UnmarshalJSON Custom UnmarshalJSON method for validating Override

type OverrideableRule added in v0.0.24

type OverrideableRule struct {
	*Rule
	Overrides []*Override `json:"overrides,omitempty"`
}

func (*OverrideableRule) BoolValue added in v0.0.24

func (t *OverrideableRule) BoolValue(version string, defaultValue bool) (bool, bool)

BoolValue retrieves a bool value of the rule and returns the default value if it does not exist and a bool on whether or not the rule exists

func (*OverrideableRule) CustomValue added in v0.0.24

func (t *OverrideableRule) CustomValue(version string, v any) error

CustomValue unmarshals v into the value of the rule

func (*OverrideableRule) Float64Value added in v0.0.24

func (t *OverrideableRule) Float64Value(version string, defaultValue float64) (float64, bool)

Float64Value retrieves a float64 value of the rule and returns the default value if it does not exist and a bool on whether or not the rule exists

func (*OverrideableRule) StringValue added in v0.0.24

func (t *OverrideableRule) StringValue(version string, defaultValue string) (string, bool)

StringValue retrieves a string value of the rule and returns the default value if it does not exist and a bool on whether or not the rule exists

func (*OverrideableRule) UnmarshalJSON added in v0.0.24

func (t *OverrideableRule) UnmarshalJSON(b []byte) error

UnmarshalJSON Custom UnmarshalJSON method for validating rule Value to the RuleType

func (*OverrideableRule) ValueAtVersion added in v0.0.25

func (t *OverrideableRule) ValueAtVersion(version string) interface{}

ValueAtVersion returns the value at the given version. Will return default value if version is empty string or no override is present for the specified version

type Realm added in v0.0.18

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

func NewRealm added in v0.0.18

func NewRealm(options ...RealmOption) (*Realm, error)

NewRealm returns a new Realm struct that carries out all of the core features

func (*Realm) Bool added in v0.0.18

func (rlm *Realm) Bool(ctx context.Context, ruleKey string, defaultValue bool) (bool, error)

Bool retrieves a bool by the key of the rule. Returns the default value if it does not exist and an error if the chamber is empty or could not be converted

func (*Realm) CustomValue added in v0.0.18

func (rlm *Realm) CustomValue(ctx context.Context, ruleKey string, v any) error

CustomValue retrieves an arbitrary value by the key of the rule and unmarshals the value into the custom value v

func (*Realm) Float64 added in v0.0.18

func (rlm *Realm) Float64(ctx context.Context, ruleKey string, defaultValue float64) (float64, error)

Float64 retrieves a float64 by the key of the rule. Returns the default value if it does not exist and an error if the chamber is empty or could not be converted

func (*Realm) NewContext added in v0.0.18

func (rlm *Realm) NewContext(ctx context.Context) context.Context

func (*Realm) Start added in v0.0.18

func (rlm *Realm) Start() error

Start starts realm and initializes the underlying chamber

func (*Realm) Stop added in v0.0.18

func (rlm *Realm) Stop()

Stop stops realm and flushes any pending tasks

func (*Realm) String added in v0.0.18

func (rlm *Realm) String(ctx context.Context, ruleKey string, defaultValue string) (string, error)

String retrieves a string by the key of the rule. Returns the default value if it does not exist and an error if the chamber is empty or could not be converted

type RealmConfig added in v0.0.25

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

type RealmOption added in v0.0.25

type RealmOption interface {
	// contains filtered or unexported methods
}

func WithHttpClient added in v0.1.1

func WithHttpClient(c *client.HttpClient) RealmOption

func WithPath added in v0.0.25

func WithPath(path string) RealmOption

func WithPollingInterval added in v0.1.1

func WithPollingInterval(d time.Duration) RealmOption

func WithVersion added in v0.0.25

func WithVersion(version string) RealmOption

type Rule added in v0.0.24

type Rule struct {
	Type  string      `json:"type"`
	Value interface{} `json:"value"`
}

Rule is a feature definition structure for holding its name, value, type and any overrides to be parsed by the applicable realm sdk

func (*Rule) UnmarshalJSON added in v0.0.24

func (t *Rule) UnmarshalJSON(b []byte) error

type UnsupportedTypeError added in v0.0.18

type UnsupportedTypeError struct {
	RuleType string
}

func (*UnsupportedTypeError) Error added in v0.0.18

func (ut *UnsupportedTypeError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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