]> ruderich.org/simon Gitweb - nsscash/nsscash.git/commitdiff
nsscash: go fmt
authorSimon Ruderich <simon@ruderich.org>
Fri, 14 Jun 2019 18:21:12 +0000 (20:21 +0200)
committerSimon Ruderich <simon@ruderich.org>
Fri, 14 Jun 2019 18:21:12 +0000 (20:21 +0200)
main.go

diff --git a/main.go b/main.go
index 0dd00294634b1759fa9bc8a59bfeeea79cffd39e..a563b511355273983d0a0ea3060a288ad64e456d 100644 (file)
--- 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
 }