代码拉取完成,页面将自动刷新
同步操作将从 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 (
"bufio"
"fmt"
"os"
"strings"
)
// WriteFile saves the configuration representation to a file.
// The desired file permissions must be passed as in os.Open. The header is a
// string that is saved as a comment in the first line of the file.
func (c *Config) WriteFile(fname string, perm os.FileMode, header string) error {
file, err := os.OpenFile(fname, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
if err != nil {
return err
}
buf := bufio.NewWriter(file)
if err = c.write(buf, header); err != nil {
return err
}
buf.Flush()
return file.Close()
}
func (c *Config) write(buf *bufio.Writer, header string) (err error) {
if header != "" {
// Add comment character after of each new line.
if i := strings.Index(header, "\n"); i != -1 {
header = strings.Replace(header, "\n", "\n"+c.comment, -1)
}
if _, err = buf.WriteString(c.comment + header + "\n"); err != nil {
return err
}
}
for _, orderedSection := range c.Sections() {
for section, sectionMap := range c.data {
if section == orderedSection {
// Skip default section if empty.
if section == DEFAULT_SECTION && len(sectionMap) == 0 {
continue
}
if _, err = buf.WriteString("\n[" + section + "]\n"); err != nil {
return err
}
// Follow the input order in options.
for i := 0; i < c.lastIdOption[section]; i++ {
for option, tValue := range sectionMap {
if tValue.position == i {
if len(tValue.vMuti) > 0 {
for _, realValue := range tValue.vMuti {
if _, err = buf.WriteString(fmt.Sprint(
"@", option, c.separator, realValue, "\n")); err != nil {
return err
}
}
} else {
if _, err = buf.WriteString(fmt.Sprint(
option, c.separator, tValue.v, "\n")); err != nil {
return err
}
}
c.RemoveOption(section, option)
break
}
}
}
}
}
}
if _, err = buf.WriteString("\n"); err != nil {
return err
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。