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 {
|
||||
var f *os.File
|
||||
var err error
|
||||
|
||||
var b []byte
|
||||
if b, err = marshal(target, filepath.Ext(file)); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
if Exists(file) {
|
||||
if !overWrite {
|
||||
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
|
||||
}
|
||||
} else {
|
||||
|
@ -173,11 +179,7 @@ func marshalFile(target interface{}, file string, overWrite bool) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var b []byte
|
||||
if b, err = marshal(target, filepath.Ext(file)); nil != err {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if _, err = f.Write(b); nil != err {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue
Block a user