setting

package
v0.0.0-...-8444db5 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSettingType  = errors.New("invalid setting type")
	ErrInvalidSettingValue = errors.New("invalid setting value")
)

Functions

func NewValidationError

func NewValidationError(err error, message string) error

Types

type ID

type ID string
const (
	AdminPassword  ID = "adminPassword"
	WelcomeMessage ID = "welcomeMessage"
)

type Metadata

type Metadata struct {
	ValueType    ValueType
	Label        string
	DefaultValue interface{}
	// contains filtered or unexported fields
}

func NewBaseMetadata

func NewBaseMetadata(valueType ValueType, label string, defaultValue interface{}) *Metadata

func NewMarkdownMetadata

func NewMarkdownMetadata(label, defaultValue string) *Metadata

func NewPasswordMetadata

func NewPasswordMetadata(label string) *Metadata

func (*Metadata) Transform

func (m *Metadata) Transform(id ID, value interface{}) (interface{}, error)

func (*Metadata) Validate

func (m *Metadata) Validate(id ID, value interface{}, form url.Values) error

type Repository

type Repository interface {
	Register(id ID, metadata *Metadata) error
	ListMetadata() (map[ID]*Metadata, error)
	GetMetadata(id ID) (*Metadata, error)
	List() ([]*Setting, error)
	Get(id ID) (*Setting, error)
	Has(id ID) (bool, error)
	Save(id ID, value interface{}) error
	Delete(id ID) error
}

type Setting

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

func NewSetting

func NewSetting(id ID, value interface{}, metadata *Metadata) *Setting

func (*Setting) AsString

func (s *Setting) AsString() (string, error)

func (*Setting) ID

func (s *Setting) ID() ID

func (*Setting) Metadata

func (s *Setting) Metadata() *Metadata

func (*Setting) Value

func (s *Setting) Value() interface{}

type TransformFunc

type TransformFunc func(id ID, value interface{}, metadata *Metadata) (interface{}, error)

type ValidateFunc

type ValidateFunc func(id ID, value interface{}, metadata *Metadata, form url.Values) error

type ValidationMessage

type ValidationMessage interface {
	error

	ValidationMessage() string
}

type ValueType

type ValueType string
const (
	ValueTypeText     ValueType = "text"
	ValueTypeMarkdown ValueType = "markdown"
	ValueTypePassword ValueType = "password"
)

Jump to

Keyboard shortcuts

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