confile

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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