config

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2019 License: MIT Imports: 7 Imported by: 6

README

conv Build Status

安装
go get github.com/issue9/config
文档

Go Walker GoDoc

版权

本项目采用MIT开源授权许可证,完整的授权说明可在LICENSE文件中找到。

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

Error 配置文件错误信息

func NewError

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

NewError 声明新的 Error 对象

func (*Error) Error

func (err *Error) Error() string

type Manager

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

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

func NewManager

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

NewManager 新的 Manager 实例

func (*Manager) AddUnmarshal

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

AddUnmarshal 注册解析函数

func (*Manager) Exists

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

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

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

func (*Manager) File

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

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

func (*Manager) Load

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

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

func (*Manager) LoadFile

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

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

func (*Manager) SetUnmarshal

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