config

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config 提供了对多种格式配置文件的支持

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error added in v0.21.0

type Error struct {
	File    string // 文件地址
	Field   string // 字段名称
	Message string // 错误信息
}

Error 配置文件错误信息

func NewError added in v0.21.0

func NewError(file, field, message string) *Error

NewError 声明新的 Error 对象

func (*Error) Error added in v0.21.0

func (err *Error) Error() string

type Manager added in v0.18.0

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

Manager 对 UnmarshalFunc 与扩展名的关联管理。

func NewManager added in v0.18.0

func NewManager(dir string) (*Manager, error)

NewManager 新的 Manager 实例

func (*Manager) AddUnmarshal added in v0.18.0

func (mgr *Manager) AddUnmarshal(m UnmarshalFunc, ext ...string) error

AddUnmarshal 注册解析函数

func (*Manager) Exists added in v0.21.0

func (mgr *Manager) Exists(ext string) bool

Exists 是否已经存在该类型的解析函数

ext 表示该类型的文件扩展名,带 . 符号

func (*Manager) File added in v0.18.0

func (mgr *Manager) File(path string) string

File 获取文件路径,相对于当前配置目录

func (*Manager) Load added in v0.18.0

func (mgr *Manager) Load(r io.Reader, typ string, v interface{}) error

Load 加载指定的配置文件内容到 v 中

func (*Manager) LoadFile added in v0.18.0

func (mgr *Manager) LoadFile(path string, v interface{}) error

LoadFile 加载指定的配置文件内容到 v 中

func (*Manager) SetUnmarshal added in v0.18.0

func (mgr *Manager) SetUnmarshal(m UnmarshalFunc, ext ...string) error

SetUnmarshal 修改指定扩展名关联的解析函数,不存在则添加。

type Sanitizer

type Sanitizer interface {
	// 对对象的各个字段进行检测,如果可以调整,则调整。
	// 如果不能调整,则返回错误信息。返回的错误信息,
	// 尽可能是 *Error 对象。
	Sanitize() error
}

Sanitizer 如果对象实现了该方法,那么在解析完之后, 会调用该接口的函数对数据进行修正和检测。

type UnmarshalFunc

type UnmarshalFunc func([]byte, interface{}) error

UnmarshalFunc 定义了将文本内容解析到对象的函数原型。

Jump to

Keyboard shortcuts

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