model

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package model provides dev projects and flag override data models for the api handler to use. It exists so that it can also notify observers to support streaming updates

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyExists = errors.New("already exists")
View Source
var ErrNotFound = errors.New("not found")

Functions

func ContextWithStore

func ContextWithStore(ctx context.Context, store Store) context.Context

func NewError

func NewError(message string) error

func ObserversMiddleware

func ObserversMiddleware(observers *Observers) func(handler http.Handler) http.Handler

func SetObserversOnContext

func SetObserversOnContext(ctx context.Context, observers *Observers) context.Context

func StoreMiddleware

func StoreMiddleware(store Store) mux.MiddlewareFunc

Types

type Environment added in v1.6.0

type Environment struct {
	Key  string
	Name string
}

func GetEnvironmentsForProject added in v1.6.0

func GetEnvironmentsForProject(ctx context.Context, projectKey string, query string, limit *int) ([]Environment, error)

type Error

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

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type FlagState

type FlagState struct {
	Value   ldvalue.Value `json:"value"`
	Version int           `json:"version"`
}

type FlagVariation added in v1.5.0

type FlagVariation struct {
	FlagKey string
	Variation
}

type FlagsState

type FlagsState map[string]FlagState

func FromAllFlags

func FromAllFlags(sdkFlags flagstate.AllFlags) FlagsState

type Observer

type Observer interface {
	Handle(interface{})
}

type Observers

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

func GetObserversFromContext

func GetObserversFromContext(ctx context.Context) *Observers

func NewObservers

func NewObservers() *Observers

func (*Observers) DeregisterObserver

func (o *Observers) DeregisterObserver(observerId uuid.UUID) bool

func (*Observers) Notify

func (o *Observers) Notify(event interface{})

func (*Observers) RegisterObserver

func (o *Observers) RegisterObserver(observer Observer) uuid.UUID

type Override

type Override struct {
	ProjectKey string
	FlagKey    string
	Value      ldvalue.Value
	Active     bool
	Version    int
}

func UpsertOverride

func UpsertOverride(ctx context.Context, projectKey, flagKey string, value ldvalue.Value) (Override, error)

func (Override) Apply

func (o Override) Apply(state FlagState) FlagState

type Overrides

type Overrides []Override

func (Overrides) GetFlag

func (o Overrides) GetFlag(key string) (Override, bool)

type Project

type Project struct {
	Key                  string
	SourceEnvironmentKey string
	Context              ldcontext.Context
	LastSyncTime         time.Time
	AllFlagsState        FlagsState
	AvailableVariations  []FlagVariation
}

func CreateProject

func CreateProject(ctx context.Context, projectKey, sourceEnvironmentKey string, ldCtx *ldcontext.Context) (Project, error)

CreateProject creates a project and adds it to the database.

func UpdateProject

func UpdateProject(ctx context.Context, projectKey string, context *ldcontext.Context, sourceEnvironmentKey *string) (Project, error)

func (Project) GetFlagStateWithOverridesForProject

func (project Project) GetFlagStateWithOverridesForProject(ctx context.Context) (FlagsState, error)

type Store

type Store interface {
	DeactivateOverride(ctx context.Context, projectKey, flagKey string) error
	GetDevProjectKeys(ctx context.Context) ([]string, error)
	// GetDevProject fetches the project based on the projectKey. If it doesn't exist, ErrNotFound is returned
	GetDevProject(ctx context.Context, projectKey string) (*Project, error)
	UpdateProject(ctx context.Context, project Project) (bool, error)
	DeleteDevProject(ctx context.Context, projectKey string) (bool, error)
	// InsertProject inserts the project. If it already exists, ErrAlreadyExists is returned
	InsertProject(ctx context.Context, project Project) error
	UpsertOverride(ctx context.Context, override Override) (Override, error)
	GetOverridesForProject(ctx context.Context, projectKey string) (Overrides, error)
	GetAvailableVariationsForProject(ctx context.Context, projectKey string) (map[string][]Variation, error)
}

func StoreFromContext

func StoreFromContext(ctx context.Context) Store

type SyncEvent

type SyncEvent struct {
	ProjectKey    string
	AllFlagsState FlagsState
}

Event for full project sync

type UpsertOverrideEvent

type UpsertOverrideEvent struct {
	FlagKey    string
	ProjectKey string
	FlagState  FlagState
}

Event for individual flag overrides

type Variation added in v1.5.0

type Variation struct {
	Id          string
	Description *string
	Name        *string
	Value       ldvalue.Value
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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