package setting

import "github.com/go-arrower/arrower/setting"

Index

Variables

var (
	ErrNotFound     = errors.New("not found")
	ErrInvalidValue = errors.New("invalid value")
)
var ErrOperationFailed = errors.New("operation failed")

Functions

func TestSuite

func TestSuite(t *testing.T, newSettings func() Settings)

Types

type InMemorySettings

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

func NewInMemorySettings

func NewInMemorySettings() *InMemorySettings

func (*InMemorySettings) Delete

func (s *InMemorySettings) Delete(ctx context.Context, key Key) error

func (*InMemorySettings) Save

func (s *InMemorySettings) Save(ctx context.Context, key Key, setting Value) error

func (*InMemorySettings) Setting

func (s *InMemorySettings) Setting(ctx context.Context, key Key) (Value, error)

func (*InMemorySettings) Settings

func (s *InMemorySettings) Settings(ctx context.Context, keys []Key) (map[Key]Value, error)

type Key

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

func NewKey

func NewKey(context string, group string, setting string) Key

func (Key) Key

func (k Key) Key() string

type PostgresSettings

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

func NewPostgresSettings

func NewPostgresSettings(pgxPool *pgxpool.Pool) *PostgresSettings

func (*PostgresSettings) Delete

func (s *PostgresSettings) Delete(ctx context.Context, key Key) error

func (*PostgresSettings) Save

func (s *PostgresSettings) Save(ctx context.Context, key Key, value Value) error

func (*PostgresSettings) Setting

func (s *PostgresSettings) Setting(ctx context.Context, key Key) (Value, error)

func (*PostgresSettings) Settings

func (s *PostgresSettings) Settings(ctx context.Context, keys []Key) (map[Key]Value, error)

type Settings

type Settings interface {
	Save(ctx context.Context, key Key, value Value) error

	Setting(ctx context.Context, key Key) (Value, error)
	// Settings returns a setting for each of the keys.
	// If not all keys exist, the found settings are returned anyway with an ErrNotFound error.
	Settings(ctx context.Context, keys []Key) (map[Key]Value, error)

	Delete(ctx context.Context, key Key) error
}

type Value

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

func NewValue

func NewValue(val any) Value

NewValue returns a valid Value for val.

func (Value) Bool

func (v Value) Bool() (bool, error)

func (Value) Byte

func (v Value) Byte() ([]byte, error)

func (Value) Float32

func (v Value) Float32() (float32, error)

func (Value) Float64

func (v Value) Float64() (float64, error)

func (Value) Int

func (v Value) Int() (int, error)

func (Value) Int16

func (v Value) Int16() (int16, error)

func (Value) Int32

func (v Value) Int32() (int32, error)

func (Value) Int64

func (v Value) Int64() (int64, error)

func (Value) Int8

func (v Value) Int8() (int8, error)

func (Value) MustBool

func (v Value) MustBool() bool

func (Value) MustByte

func (v Value) MustByte() []byte

func (Value) MustFloat32

func (v Value) MustFloat32() float32

func (Value) MustFloat64

func (v Value) MustFloat64() float64

func (Value) MustInt

func (v Value) MustInt() int

func (Value) MustInt16

func (v Value) MustInt16() int16

func (Value) MustInt32

func (v Value) MustInt32() int32

func (Value) MustInt64

func (v Value) MustInt64() int64

func (Value) MustInt8

func (v Value) MustInt8() int8

func (Value) MustString

func (v Value) MustString() string

func (Value) MustTime

func (v Value) MustTime() time.Time

func (Value) MustUint

func (v Value) MustUint() uint

func (Value) MustUint16

func (v Value) MustUint16() uint16

func (Value) MustUint32

func (v Value) MustUint32() uint32

func (Value) MustUint64

func (v Value) MustUint64() uint64

func (Value) MustUint8

func (v Value) MustUint8() uint8

func (Value) MustUnmarshal

func (v Value) MustUnmarshal(o any)

func (Value) Raw

func (v Value) Raw() string

Raw returns the raw string value of Value as created by NewValue. The main purpose is to aid when implementing persistent implementations of Settings, as some types like time have a composite format. Each part is separated by the timeLocationSeparator.

func (Value) String

func (v Value) String() (string, error)

func (Value) Time

func (v Value) Time() (time.Time, error)

func (Value) Uint

func (v Value) Uint() (uint, error)

func (Value) Uint16

func (v Value) Uint16() (uint16, error)

func (Value) Uint32

func (v Value) Uint32() (uint32, error)

func (Value) Uint64

func (v Value) Uint64() (uint64, error)

func (Value) Uint8

func (v Value) Uint8() (uint8, error)

func (Value) Unmarshal

func (v Value) Unmarshal(o any) error

Source Files

inmemory.settings.go postgres.settings.go settings.go testing.go

Directories

PathSynopsis
setting/models
Version
v0.0.0-20250311203644-ab26c1152cb4 (latest)
Published
Mar 11, 2025
Platform
linux/amd64
Imports
15 packages
Last checked
1 week ago

Tools for package owners.