2020-10-08 20:47:59 +02:00
|
|
|
package main
|
2020-10-08 18:21:27 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FileExists returns true if a file exists at the path
|
2020-10-08 20:47:59 +02:00
|
|
|
func fileExists(path string) bool {
|
2020-10-08 18:21:27 +02:00
|
|
|
_, err := os.Stat(path)
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return err == nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateGUID returns a random GUID
|
2020-10-08 20:47:59 +02:00
|
|
|
func createGUID() string {
|
2020-10-08 18:21:27 +02:00
|
|
|
b := make([]byte, 16)
|
|
|
|
_, err := rand.Read(b)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
uuid := fmt.Sprintf("%x-%x-%x-%x-%x",
|
|
|
|
b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
|
|
|
|
|
|
|
|
return uuid
|
|
|
|
}
|