From 78239472f30846add39a4f14455cc92aba8ea79b Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 14 Jun 2019 20:21:12 +0200 Subject: [PATCH] nsscash: go fmt --- main.go | 118 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/main.go b/main.go index 0dd0029..a563b51 100644 --- a/main.go +++ b/main.go @@ -72,78 +72,78 @@ func main() { } func mainFetch(cfgPath string) error { - cfg, err := LoadConfig(cfgPath) - if err != nil { - return err - } - state, err := LoadState(cfg.StatePath) - if err != nil { - return err - } - err = handleFiles(cfg, state) - if err != nil { - return err - } - // NOTE: Make sure to call WriteState() only if there were no - // errors (see WriteState() and README) - err = WriteState(cfg.StatePath, state) - if err != nil { - return err - } - return nil + cfg, err := LoadConfig(cfgPath) + if err != nil { + return err + } + state, err := LoadState(cfg.StatePath) + if err != nil { + return err + } + err = handleFiles(cfg, state) + if err != nil { + return err + } + // NOTE: Make sure to call WriteState() only if there were no + // errors (see WriteState() and README) + err = WriteState(cfg.StatePath, state) + if err != nil { + return err + } + return nil } func mainConvert(typ, srcPath, dstPath string) error { - var t FileType - err := t.UnmarshalText([]byte(typ)) + var t FileType + err := t.UnmarshalText([]byte(typ)) + if err != nil { + return err + } + + src, err := ioutil.ReadFile(srcPath) + if err != nil { + return err + } + var x bytes.Buffer + if t == FileTypePlain { + x.Write(src) + } else if t == FileTypePasswd { + pws, err := ParsePasswds(bytes.NewReader(src)) if err != nil { return err } - - src, err := ioutil.ReadFile(srcPath) + err = SerializePasswds(&x, pws) if err != nil { return err } - var x bytes.Buffer - if t == FileTypePlain { - x.Write(src) - } else if t == FileTypePasswd { - pws, err := ParsePasswds(bytes.NewReader(src)) - if err != nil { - return err - } - err = SerializePasswds(&x, pws) - if err != nil { - return err - } - } else if t == FileTypeGroup { - grs, err := ParseGroups(bytes.NewReader(src)) - if err != nil { - return err - } - err = SerializeGroups(&x, grs) - if err != nil { - return err - } - } else { - return fmt.Errorf("unsupported file type %v", t) - } - - // We must create the file first or deployFile() will abort - f, err := os.Create(dstPath) + } else if t == FileTypeGroup { + grs, err := ParseGroups(bytes.NewReader(src)) if err != nil { return err } - f.Close() - - err = deployFile(&File{ - Type: t, - Url: srcPath, - Path: dstPath, - body: x.Bytes(), - }) + err = SerializeGroups(&x, grs) if err != nil { return err } - return nil + } else { + return fmt.Errorf("unsupported file type %v", t) + } + + // We must create the file first or deployFile() will abort + f, err := os.Create(dstPath) + if err != nil { + return err + } + f.Close() + + err = deployFile(&File{ + Type: t, + Url: srcPath, + Path: dstPath, + body: x.Bytes(), + }) + if err != nil { + return err + } + return nil } -- 2.45.2