diff --git a/util.go b/util.go index bd601bb..f509f65 100644 --- a/util.go +++ b/util.go @@ -159,7 +159,6 @@ 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 @@ -171,21 +170,9 @@ func marshalFile(target interface{}, file string, overWrite bool) error { if !overWrite { return fmt.Errorf("Config: File[%s] is exist", file) } - if f, err = os.OpenFile(file, os.O_WRONLY, os.ModeAppend); nil != err { - return err - } - } else { - if f, err = os.Create(file); nil != err { - return err - } } - defer f.Close() - - if _, err = f.Write(b); nil != err { - return err - } - return nil + return ioutil.WriteFile(file, b, os.ModeAppend) } func marshal(target interface{}, ext string) ([]byte, error) {