Documentation ¶
Overview ¶
Package confile is helper to load and overwrite configuration files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultJSONEncodingCreator = &JSONEncodingCreator{}
DefaultJSONEncodingCreator implements EncodingCreator for JSON encoding.
var DefaultTOMLEncodingCreator = &TOMLEncodingCreator{}
DefaultTOMLEncodingCreator implements EncodingCreator for TOML encoding.
var DefaultYAMLEncodingCreator = &YAMLEncodingCreator{}
DefaultYAMLEncodingCreator implements EncodingCreator for YAML encoding.
Functions ¶
This section is empty.
Types ¶
type ConfigFile ¶
type ConfigFile struct {
// contains filtered or unexported fields
}
ConfigFile represents a configuration file.
func New ¶
func New(creator EncodingCreator, path string) *ConfigFile
New starts a new ConfigFile by using creator as underlying EncodingCreator to encode and decode config file that presents or will present on path.
func (*ConfigFile) Load ¶
func (c *ConfigFile) Load(v interface{}) error
Load loads content of config file into v if file exist on path. otherwise nothing loaded into v and no error is returned.
func (*ConfigFile) Save ¶
func (c *ConfigFile) Save(v interface{}) error
Save saves v into config file by overwriting the previous content it also creates the config file if it wasn't exist.
func (*ConfigFile) SaveJSON ¶
func (c *ConfigFile) SaveJSON(v interface{}) error
SaveJSON saves v into file as JSON format
type Decoder ¶
type Decoder interface {
Decode(v interface{}) error
}
Decoder should decode a v from io.Reader given to EncodingCreator.
type EncodeDecoder ¶
EncodeDecoder combines Encoder and Decoder.
func NewEncoding ¶
func NewEncoding(e Encoder, d Decoder) EncodeDecoder
NewEncoding returns a new EncodeDecoder implementation from e end d.
type Encoder ¶
type Encoder interface {
Encode(v interface{}) error
}
Encoder should encode a v into io.Writer given to EncodingCreator.
type EncodingCreator ¶
type EncodingCreator interface {
Create(io.ReadWriter) EncodeDecoder
}
EncodingCreator defines a constructor to create an EncodingCreator from an io.ReadWriter.
type JSONEncodingCreator ¶
type JSONEncodingCreator struct{}
JSONEncodingCreator implements EncodingCreator for JSON encoding.
func (*JSONEncodingCreator) Create ¶
func (e *JSONEncodingCreator) Create(rw io.ReadWriter) EncodeDecoder
type TOMLEncodingCreator ¶
type TOMLEncodingCreator struct{}
TOMLEncodingCreator implements EncodingCreator for JSON encoding.
func (*TOMLEncodingCreator) Create ¶
func (e *TOMLEncodingCreator) Create(rw io.ReadWriter) EncodeDecoder
type YAMLEncodingCreator ¶
type YAMLEncodingCreator struct{}
YAMLEncodingCreator implements EncodingCreator for JSON encoding.
func (*YAMLEncodingCreator) Create ¶
func (e *YAMLEncodingCreator) Create(rw io.ReadWriter) EncodeDecoder