config

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config 提供了加载配置项内容的各类方法

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("id 值已经存在")

ErrNotFound 未找到与 ID 相关的项

Functions

func LoadFile added in v0.16.1

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

LoadFile 加载配置文件内容至 v

支持 yaml、xml 和 json 格式内容,以后缀名作为判断依据。

func LoadJSON added in v0.32.0

func LoadJSON(path string, v interface{}) error

LoadJSON 加载 JSON 的配置文件并转换成 v 对象的内容

func LoadXML added in v0.32.0

func LoadXML(path string, v interface{}) error

LoadXML 加载 XML 的配置文件并转换成 v 对象的内容

func LoadYAML added in v0.32.0

func LoadYAML(path string, v interface{}) error

LoadYAML 加载 YAML 的配置文件并转换成 v 对象的内容

Types

type Config added in v0.32.0

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

Config 管理配置项的加载和刷新

func New added in v0.32.0

func New(config string, v interface{}, f UnmarshalFunc, notify func()) *Config

New 注册配置项

config 表示配置项的配置内容,比如文件名、SQL 的 DSN 等; v 配置项导出对象的实例指针,最终 config 指向的数据会被解析到 v 中; f 从 config 导入到 v 的实现方法; notify 如果后期需要更新数据,则通过此函数通知用户数据已经被更新;

func (*Config) Refresh added in v0.32.0

func (cfg *Config) Refresh() error

Refresh 刷新指定 ID 的配置项

type FieldError added in v0.32.0

type FieldError struct {
	Field, Message string
}

FieldError 表示配置内容字段错误

func (*FieldError) Error added in v0.32.0

func (err *FieldError) Error() string

type UnmarshalFunc

type UnmarshalFunc func(config string, v interface{}) error

UnmarshalFunc 定义了配置项的解码函数原型

config 为配置项的配置内容,可以是一个文件名或是数据库的 DSN 等, UnmarshalFunc 负责将其指向的内容解析并映身到 v 对象。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳