ing
This commit is contained in:
parent
fb70b256fb
commit
ee725bc7d4
14
util.go
14
util.go
|
@ -161,11 +161,17 @@ func getPrefixForStruct(prefixes []string, fieldStruct *reflect.StructField) []s
|
||||||
func marshalFile(target interface{}, file string, overWrite bool) error {
|
func marshalFile(target interface{}, file string, overWrite bool) error {
|
||||||
var f *os.File
|
var f *os.File
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
var b []byte
|
||||||
|
if b, err = marshal(target, filepath.Ext(file)); nil != err {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if Exists(file) {
|
if Exists(file) {
|
||||||
if !overWrite {
|
if !overWrite {
|
||||||
return fmt.Errorf("Config: File[%s] is exist", file)
|
return fmt.Errorf("Config: File[%s] is exist", file)
|
||||||
}
|
}
|
||||||
if f, err = os.Open(file); nil != err {
|
if f, err = os.OpenFile(file, os.O_WRONLY, os.ModeAppend); nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -173,11 +179,7 @@ func marshalFile(target interface{}, file string, overWrite bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
var b []byte
|
|
||||||
if b, err = marshal(target, filepath.Ext(file)); nil != err {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = f.Write(b); nil != err {
|
if _, err = f.Write(b); nil != err {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user