confy

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: MIT Imports: 11 Imported by: 3

README

confy

A stupid simple configuration store.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMemNoKey = errors.New("no such key in DataMem")

ErrMemNoKey occurs when a given key does not exist.

Functions

This section is empty.

Types

type Confy

type Confy struct {
	Data
	Form
}

A Confy is a stupid simple configuration store.

func New

func New(s Data, f Form) *Confy

New makes a new Confy with the given Data and Form.

func (*Confy) Load

func (c *Confy) Load(key string, ptr interface{}) error

Load wraps a call to Data.Reader and Form.Unmarshal.

func (*Confy) Store

func (c *Confy) Store(key string, value interface{}) error

Store wraps a call to Data.Writer and Form.Marshal.

type Data

type Data interface {
	// Reader fetches a ReadCloser for the given key.
	Reader(key string) (io.ReadCloser, error)

	// Writer fetches a WriteCloser for the given key.
	Writer(key string) (io.WriteCloser, error)

	// Delete removes the given key if it exists.
	Delete(key string) error

	// Keys returns available keys.
	Keys() ([]string, error)
}

Data exposes a storage backend.

type DataFile added in v0.4.0

type DataFile struct {
	Base string
	Ext  string
}

DataFile is a filesystem-based Data.

func ConfigDataFile added in v0.4.0

func ConfigDataFile(app, ext string) (DataFile, error)

ConfigDataFile creates a DataFile with the given app name and file extension.

func NewDataFile added in v0.4.0

func NewDataFile(base, ext string) (DataFile, error)

NewDataFile creates a DataFile with a given base directory and file extension.

func (DataFile) Delete added in v0.4.0

func (d DataFile) Delete(key string) error

Delete removes the given key if it exists - in this case, using os.Remove.

func (DataFile) Keys added in v0.4.0

func (d DataFile) Keys() ([]string, error)

Keys returns available keys - in this case, using os.ReadDir.

func (DataFile) Reader added in v0.4.0

func (d DataFile) Reader(key string) (io.ReadCloser, error)

Reader fetches a ReadCloser for the given key - in this case, using os.Open.

func (DataFile) Writer added in v0.4.0

func (d DataFile) Writer(key string) (io.WriteCloser, error)

Writer fetches a WriteCloser for the given key - in this case, using os.Create.

type DataMem added in v0.4.0

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

DataMem is a concurrent-safe, in-memory Data.

func NewDataMem added in v0.4.0

func NewDataMem() DataMem

NewDataMem creates a usable DataMem.

func (DataMem) Delete added in v0.4.0

func (d DataMem) Delete(key string) error

Delete removes the given key if it exists - in this case, using internal maps and locks.

func (DataMem) Keys added in v0.4.0

func (d DataMem) Keys() ([]string, error)

Keys returns available keys - in this case, using internal maps and locks.

func (DataMem) Reader added in v0.4.0

func (d DataMem) Reader(key string) (io.ReadCloser, error)

Reader fetches a ReadCloser for the given key - in this case, using internal maps and locks.

func (DataMem) Writer added in v0.4.0

func (d DataMem) Writer(key string) (io.WriteCloser, error)

Writer fetches a WriteCloser for the given key - in this case, using internal maps and locks.

type Form

type Form interface {
	// Marshal encodes the given value into the given Writer.
	Marshal(w io.Writer, value interface{}) error

	// Unmarshal decodes the given Reader into the given pointer.
	Unmarshal(r io.Reader, ptr interface{}) error
}

Form describes an object encoding format.

type FormJSON added in v0.4.0

type FormJSON struct {
	// Marshal options
	EscapeHTML bool
	Prefix     string
	Indent     string

	// Unmarshal options
	DisallowUnknownFields bool
	UseNumber             bool
}

FormJSON is a JSON-based Form, ideal for structured data.

func (FormJSON) Marshal added in v0.4.0

func (f FormJSON) Marshal(w io.Writer, value interface{}) error

Marshal encodes the given value into the given Writer - in this case, using json.NewEncoder.

func (FormJSON) Unmarshal added in v0.4.0

func (f FormJSON) Unmarshal(r io.Reader, value interface{}) error

Unmarshal decodes the given Reader into the given pointer - in this case, using json.NewDecoder.

type FormYAML added in v0.4.0

type FormYAML struct {
	// Marshal options
	Indent int

	// Unmarshal options
	KnownFields bool
}

FormYAML is a YAML-based Form, ideal for readable configuration.

func (FormYAML) Marshal added in v0.4.0

func (f FormYAML) Marshal(w io.Writer, value interface{}) error

Marshal encodes the given value into the given Writer - in this case, using yaml.NewEncoder.

func (FormYAML) Unmarshal added in v0.4.0

func (f FormYAML) Unmarshal(r io.Reader, value interface{}) error

Unmarshal decodes the given Reader into the given pointer - in this case, using yaml.NewDecoder.

Jump to

Keyboard shortcuts

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