options

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: MIT Imports: 7 Imported by: 1

README

options

介绍

options package for nrgo

使用说明
创建配置集合
// Options 定义
type Options struct

// 全新创建
opts := NewOptions()

// 通过设置一个配置值来快速创建一个配置结合
opts := WithOption(`name`, `value`)
配置结合基本操作
// 向配置集合中添加或覆盖一个配置项
// 向配置根节点添加配置项
opts.WithOption(`newname`, `newvalue`)

// 向配置中添加指定节点的配置项
opts.WithOption(`root:sub:name`, `subvalue`)
opts.WithOption(`root:sub:name1`, `subvalue1`)

// 获取指定节点值
opts.Value(`newname`) 			// newvalue
opts.Value(`root:sub:name1`)	//subvalue1

// 获取子节点
opts.Section(`root:sub`)		// *Options {name: subvalue, name1: subvalue1}
合并操作
// Append 向配置集合中合并多个配置集合
//	@opts 需要追加合并的配置集合
func (o *Options) Append(opts ...*Options)

// Merge 向配置根集合中合并一组配置
//	@prefix 合并目标的前缀,合并后的节点名称未 [prefix[name]]
//	@options 配置集合
func (o *Options) Merge(prefix string, options map[string]interface{})

// MergeYaml 向配置集合中合并来自 yaml 数据的配置集合
//	@yamlData yaml 数据
//	errors
//		ErrEmptyOptionsYaml 	Yaml数据为空
//		ErrResolveOptionsYaml 	Yaml数据解析失败
func (o *Options) MergeYaml(yamlData []byte) error

// MergeYamlFile 向配置集合中合并来自 yaml 文件的配置集合
// @filePath 配置文件路径
//	errors
//		ErrOpenOptionsFile 打开配置文件失败
func (o *Options) MergeYamlFile(filePath string) error

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyOptionsYaml   = errors.New(`empty yaml content of options`)
	ErrResolveOptionsYaml = errors.New(`resolve options from yaml failed`)
	ErrOpenOptionsFile    = errors.New(`open options file failed`)
)

Functions

This section is empty.

Types

type Options

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

Options 配置集合

func NewOptions

func NewOptions() *Options

NewOptions 创建一个新的配置集合

func WithOption

func WithOption(name string, value interface{}) *Options

WithOption 通过设置一个配置值来快速创建一个配置结合

@name 配置项名称 格式为 xx:xx:xx
@value 配置项值
returns
	@*Options 配置集合

func (*Options) Append added in v0.1.1

func (o *Options) Append(opts ...*Options)

Append 向配置集合中合并多个配置集合

@opts 需要追加合并的配置集合

func (*Options) Merge

func (o *Options) Merge(prefix string, options map[string]interface{})

Merge 向配置根集合中合并一组配置

@prefix 合并目标的前缀,合并后的节点名称未 [prefix[name]]
@options 配置集合

func (*Options) MergeYaml

func (o *Options) MergeYaml(yamlData []byte) error

MergeYaml 向配置集合中合并来自 yaml 数据的配置集合

@yamlData yaml 数据
errors
	ErrEmptyOptionsYaml 	Yaml数据为空
	ErrResolveOptionsYaml 	Yaml数据解析失败

func (*Options) MergeYamlFile

func (o *Options) MergeYamlFile(filePath string) error

MergeYamlFile 向配置集合中合并来自 yaml 文件的配置集合 @filePath 配置文件路径

errors
	ErrOpenOptionsFile 打开配置文件失败

func (*Options) Section

func (o *Options) Section(name string) *Options

Section 查询指定的子配置集合

@name 配置项名称 格式为 xx:xx:xx
returns
	@&Options 子配置集合

func (*Options) Value

func (o *Options) Value(name string) interface{}

Value 查询指定配置项的值,未查询到时将返回 nil

@name 配置项名称 格式为 xx:xx:xx
returns
	@interface 配置项值

func (*Options) WithOption

func (o *Options) WithOption(name string, value interface{})

WithOption 向配置集合中添加或覆盖一个配置项

@name 配置项名称 格式为 xx:xx:xx
@value 配置项值

Jump to

Keyboard shortcuts

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