copy config file to backup if unmarshal error occurs

This commit is contained in:
Drew Weymouth
2023-02-19 14:41:12 -08:00
parent a83e21d7ea
commit c9cd0922ea
2 changed files with 28 additions and 1 deletions
+19
View File
@@ -1,7 +1,9 @@
package util
import (
"io"
"math/rand"
"os"
"time"
)
@@ -18,3 +20,20 @@ func ShuffleSlice(a []int) {
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(a), func(i, j int) { a[i], a[j] = a[j], a[i] })
}
func CopyFile(srcPath, dstPath string) error {
fin, err := os.Open(srcPath)
if err != nil {
return err
}
defer fin.Close()
fout, err := os.Create(dstPath)
if err != nil {
return err
}
defer fout.Close()
_, err = io.Copy(fout, fin)
return err
}