confile

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package confile is helper to load and overwrite configuration files.

Index

Constants

This section is empty.

Variables

View Source
var DefaultJSONEncodingCreator = &JSONEncodingCreator{}

DefaultJSONEncodingCreator implements EncodingCreator for JSON encoding.

View Source
var DefaultTOMLEncodingCreator = &TOMLEncodingCreator{}

DefaultTOMLEncodingCreator implements EncodingCreator for TOML encoding.

View Source
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.

type Decoder

type Decoder interface {
	Decode(v interface{}) error
}

Decoder should decode a v from io.Reader given to EncodingCreator.

type EncodeDecoder

type EncodeDecoder interface {
	Encoder
	Decoder
}

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 Encoding

type Encoding struct {
	Encoder
	Decoder
}

Encoding implements EncodeDecoder

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

type TOMLEncodingCreator

type TOMLEncodingCreator struct{}

TOMLEncodingCreator implements EncodingCreator for JSON encoding.

func (*TOMLEncodingCreator) Create

type YAMLEncodingCreator

type YAMLEncodingCreator struct{}

YAMLEncodingCreator implements EncodingCreator for JSON encoding.

func (*YAMLEncodingCreator) Create

Jump to

Keyboard shortcuts

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