代码拉取完成,页面将自动刷新
同步操作将从 ShirDon-廖显东/go配置文件解析器 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
//++++++++++++++++++++++++++++++++++++++++
//Fighting for great,share generate value!
//Build the best soft by golang,let's go!
//++++++++++++++++++++++++++++++++++++++++
//Author:ShirDon <http://www.shirdon.com>
//Email:hcbsts@163.com; 823923263@qq.com
//++++++++++++++++++++++++++++++++++++++++
package config
import "errors"
// AddOption adds a new option and value to the configuration.
//
// If the section is nil then uses the section by default; if it does not exist,
// it is created in advance.
//
// It returns true if the option and value were inserted, and false if the value
// was overwritten.
func (c *Config) AddOption(section string, option string, value string) bool {
c.AddSection(section) // Make sure section exists
if section == "" {
section = DEFAULT_SECTION
}
_, ok := c.data[section][option]
// Add muti key process
// muti key will start with MUTI_KEY_IDENTIFIER and may appear more than once
// key will be key except MUTI_KEY_IDENTIFIER and value will be an array
if MUTI_KEY_IDENTIFIER == string(option[0]) {
option = string(option[1:])
var vMuti []string
val, ok := c.data[section][option]
if true == ok {
vMuti = val.vMuti
} else {
vMuti = []string{}
}
vMuti = append(vMuti, value)
c.data[section][option] = &tValue{c.lastIdOption[section], value, vMuti}
} else {
c.data[section][option] = &tValue{c.lastIdOption[section], value, []string{}}
}
c.lastIdOption[section]++
return !ok
}
// RemoveOption removes a option and value from the configuration.
// It returns true if the option and value were removed, and false otherwise,
// including if the section did not exist.
func (c *Config) RemoveOption(section string, option string) bool {
if _, ok := c.data[section]; !ok {
return false
}
_, ok := c.data[section][option]
delete(c.data[section], option)
return ok
}
// HasOption checks if the configuration has the given option in the section.
// It returns false if either the option or section do not exist.
func (c *Config) HasOption(section string, option string) bool {
if _, ok := c.data[section]; !ok {
return false
}
_, okd := c.data[DEFAULT_SECTION][option]
_, oknd := c.data[section][option]
return okd || oknd
}
// Options returns the list of options available in the given section.
// It returns an error if the section does not exist and an empty list if the
// section is empty. Options within the default section are also included.
func (c *Config) Options(section string) (options []string, err error) {
if _, ok := c.data[section]; !ok {
return nil, errors.New(SectionError(section).Error())
}
// Keep a map of option names we've seen to deduplicate.
optionMap := make(map[string]struct{},
len(c.data[DEFAULT_SECTION])+len(c.data[section]))
for s, _ := range c.data[DEFAULT_SECTION] {
optionMap[s] = struct{}{}
}
for s, _ := range c.data[section] {
optionMap[s] = struct{}{}
}
// Get the keys.
i := 0
options = make([]string, len(optionMap))
for k, _ := range optionMap {
options[i] = k
i++
}
return options, nil
}
// SectionOptions returns only the list of options available in the given section.
// Unlike Options, SectionOptions doesn't return options in default section.
// It returns an error if the section doesn't exist.
func (c *Config) SectionOptions(section string) (options []string, err error) {
if _, ok := c.data[section]; !ok {
return nil, errors.New(SectionError(section).Error())
}
options = make([]string, len(c.data[section]))
i := 0
for s, _ := range c.data[section] {
options[i] = s
i++
}
return options, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。