model

package
v1.17.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: Apache-2.0 Imports: 14 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

This section is empty.

Functions

func ContextWithStore

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

func CreateOrSyncProject added in v1.9.0

func CreateOrSyncProject(ctx context.Context, settings InitialProjectSettings) error

func DeleteOverride added in v1.8.1

func DeleteOverride(ctx context.Context, projectKey, flagKey string) error

func DeleteOverrides added in v1.14.0

func DeleteOverrides(ctx context.Context, projectKey string) error

func ObserversMiddleware

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

func RestoreDb added in v1.12.0

func RestoreDb(ctx context.Context, stream io.Reader) error

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 ErrAlreadyExists

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

func NewErrAlreadyExists added in v1.13.0

func NewErrAlreadyExists(kind, key string) ErrAlreadyExists

func (ErrAlreadyExists) Error added in v1.13.0

func (e ErrAlreadyExists) Error() string

type ErrNotFound

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

func NewErrNotFound added in v1.13.0

func NewErrNotFound(kind, key string) ErrNotFound

func (ErrNotFound) Error added in v1.13.0

func (e ErrNotFound) Error() string

type FlagState

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

type FlagValue added in v1.9.0

type FlagValue = ldvalue.Value

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 InitialProjectSettings added in v1.9.0

type InitialProjectSettings struct {
	Enabled    bool
	ProjectKey string
	EnvKey     string
	Context    *ldcontext.Context   `json:"context,omitempty"`
	Overrides  map[string]FlagValue `json:"overrides,omitempty"`
	SyncOnce   bool
}

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 OverrideEvent added in v1.8.1

type OverrideEvent struct {
	FlagKey    string
	ProjectKey string
	FlagState  FlagState
}

Event for individual flag overrides

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 deactivates the override for the flag, returning the updated version of the override.
	// ErrNotFound is returned if there isn't an override for the flag.
	DeactivateOverride(ctx context.Context, projectKey, flagKey string) (int, 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)

	CreateBackup(ctx context.Context) (io.ReadCloser, int64, error)
	RestoreBackup(ctx context.Context, stream io.Reader) (string, error)
}

func StoreFromContext

func StoreFromContext(ctx context.Context) Store

type SyncEvent

type SyncEvent struct {
	ProjectKey    string
	AllFlagsState FlagsState
}

Event for full project sync

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