示例#1
0
文件: config.go 项目: zotgene/loadcat
func LoadFile(name string) error {
	f, err := os.Open(name)
	if os.IsNotExist(err) {
		f, err = os.Create(name)
		if err != nil {
			return err
		}
		err = toml.NewEncoder(f).Encode(Current)
		if err != nil {
			return err
		}
		err = f.Close()
		if err != nil {
			return err
		}
		return nil
	}
	if err != nil {
		return err
	}
	err = toml.NewDecoder(f).Decode(&Current)
	if err != nil {
		return err
	}
	return nil
}
示例#2
0
// NewEncoder produces a struct capable of writing TOML-encoded data to the
// provided io.Writer. This function was originally provided by BurntSushi/toml
func NewEncoder(w io.Writer) *toml.Encoder {
	return toml.NewEncoder(w)
}
示例#3
0
func WriteConfig(w io.Writer, d interface{}) error {
	enc := toml.NewEncoder(w)
	return enc.Encode(d)
}