Documentation ¶
Overview ¶
Package storage defines the API over interfaces, which are needed to store data.
Index ¶
- Constants
- Variables
- func LoadTxt(filename string, txt *Txt) error
- func WriteTxt(txt *Txt, filename string) error
- type Field
- type Fields
- type Getter
- type Setter
- type StoragerS
- type Txt
- func (txt *Txt) AddField(f Field) error
- func (txt *Txt) Clean()
- func (txt *Txt) Get(fieldID string) (interface{}, bool)
- func (txt *Txt) GetBool(fieldID string) (bool, bool)
- func (txt *Txt) GetField(fieldID string) (Field, bool)
- func (txt *Txt) GetFields() (Fields, error)
- func (txt *Txt) GetInt(fieldID string) (int, bool)
- func (txt *Txt) GetSliceString(fieldID string) ([]string, bool)
- func (txt *Txt) GetString(fieldID string) (string, bool)
- func (txt *Txt) Marshal() ([]byte, error)
- func (txt *Txt) Set(fieldID string, value interface{}) error
- func (txt *Txt) Unmarshal(b []byte) error
Constants ¶
View Source
const ( TypeString = "string" TypeInt = "int" TypeBool = "bool" TypeSliceString = "list" )
Variables ¶
View Source
var ErrFieldNotSupported = errors.New("Field is not supported!")
ErrFieldNotSupported is used, when the field is not inside the txt storage.
View Source
var ErrTypeNotSupported = errors.New("Type is not supported!")
ErrTypeNotSupported is used when the type of the interface is not able to stored inside the txt.
View Source
var ErrWrongType = errors.New("Input has the wrong type!")
ErrWrongType is used when the given type does not match to the fieldID.
Functions ¶
Types ¶
type Field ¶
type Field struct { // Key is a unique identifier for the field Key string `yaml:"key"` // Name of the field, does not have to be unique Name string `yaml:"name"` // Type of the field must match with the defined types // inside of the Data type. Type string `yaml:"type"` // Render can be set, when there should be a different // field inside the gui. For example a string could be rendered // as a textarea Render string `yaml:"render"` // The name of a group the field is used. Group string `yaml:"group"` // Items are ordered inside the group. Order int `yaml:"order"` }
Field defines all fields for an item.
type Getter ¶
type Getter interface { Get(fieldID string) (interface{}, bool) GetInt(fieldID string) (int, bool) GetString(fieldID string) (string, bool) GetBool(fieldID string) (bool, bool) }
Getter is used to get data out of the storage
type StoragerS ¶
type StoragerS interface { Setter Getter //AddField(Field) error GetFields() (Fields, error) Marshal() ([]byte, error) Unmarshal([]byte) error }
Storager combines the interfaces
type Txt ¶
type Txt struct { Fields []Field `json:"fields"` Strings map[string]string `json:"string"` Integers map[string]int `json:"int"` Bools map[string]bool `json:"bool"` SliceStrings map[string][]string `json:"list"` }
Txt is a txt based storager
func (*Txt) Clean ¶
func (txt *Txt) Clean()
Clean removes all values which are not defined as field.
Click to show internal directories.
Click to hide internal directories.