config

package
v0.0.0-...-ae40e7c Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package config 包含解析配置文件相关工具

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(kind string, parser ConfigParser)

Register 注册ConfigParser

Types

type Config

type Config interface {
	// GlobalSection 获取全局配置段
	GlobalSection() Section
	// Section 根据name获取指定名称的配置段
	Section(name string) (Section, bool)
	// Sections 返回全部节
	Sections() []Section
}

配置信息存储接口

func NewConfig

func NewConfig(kind string, path string) (Config, error)

NewConfig 创建一个新的Config

path:配置文件路径

func NewConfigWithContent

func NewConfigWithContent(kind string, content []byte) (Config, error)

NewConfigWithContent 创建一个新的Config

content:配置文件内容

type ConfigParser

type ConfigParser func([]byte) (Config, error)

配置解析方法

type Error

type Error string

错误信息

const (
	ErrorInvalidConfigParser   Error = "ErrorInvalidConfigParser(C10000):无效的配置解析器"
	ErrorInvalidKey            Error = "ErrorInvalidKey(C10010):无效的key(%s)"
	ErrorInvalidTypeConvertion Error = "ErrorInvalidTypeConvertion(C10020):无效的类型转换,string(%s)转换为%s"
	ErrorInvalidConfigKind     Error = "ErrorInvalidConfigKind(C10030):无效的配置类型(%s)"
	ErrorReadError             Error = "ErrorReadError(C10040):无法读取配置文件(%s)"
	ErrorNotMatch              Error = "ErrorNotMatch(C10050):未找到匹配的字符(%s)"
)

错误码

func (Error) Error

func (this Error) Error() error

Error 生成error类型

func (Error) Format

func (this Error) Format(data ...interface{}) Error

Format 格式化错误信息并生成新的错误信息

func (Error) String

func (this Error) String() string

String 返回错误字符串描述

type IniConfig

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

Ini配置

func (*IniConfig) GlobalSection

func (this *IniConfig) GlobalSection() Section

GlobalSection 获取全局配置段

func (*IniConfig) Section

func (this *IniConfig) Section(name string) (Section, bool)

Section 根据name获取指定名称的配置段

func (*IniConfig) Sections

func (this *IniConfig) Sections() []Section

Sections 返回全部节

type IniSection

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

Ini配置段

func (*IniSection) Bool

func (this *IniSection) Bool(key string) (bool, error)

Bool 获取布尔值

func (*IniSection) Float

func (this *IniSection) Float(key string) (float64, error)

Float 获取浮点值

func (*IniSection) Int

func (this *IniSection) Int(key string) (int, error)

Int 获取整数

func (*IniSection) Name

func (this *IniSection) Name() string

Name 配置段名称

func (*IniSection) String

func (this *IniSection) String(key string) (string, error)

String 获取字符串

type Section

type Section interface {
	// Name 配置段名称
	Name() string
	// String 获取字符串
	String(key string) (string, error)
	// Int 获取整数
	Int(key string) (int, error)
	// Bool 获取布尔值
	Bool(key string) (bool, error)
	// Float 获取浮点值
	Float(key string) (float64, error)
}

配置信息段

Jump to

Keyboard shortcuts

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