From ee725bc7d4be64b53812b7e7562eef0c18c1a120 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 22 Sep 2017 18:17:54 +0900 Subject: [PATCH] ing --- util.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/util.go b/util.go index 4024a9d..bd601bb 100644 --- a/util.go +++ b/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