summaryrefslogtreecommitdiff
path: root/internal/util.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
commitb1d92b395322f2164ccfb44b0f7caebbaece6b62 (patch)
tree2133e4045b4af4d07a98674b7ae3a234670f0305 /internal/util.go
parent3a4ae2942b43923ff98fd2eca8878c3cf145686c (diff)
Refactor: Restructure project
- Add an internal folder where all the internal code lives - Make a state.go and state_test.go for the public interface This gives a more clear separation between functions and modules. It also makes this a more typical Go project setup.
Diffstat (limited to 'internal/util.go')
-rw-r--r--internal/util.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/util.go b/internal/util.go
new file mode 100644
index 0000000..02855c2
--- /dev/null
+++ b/internal/util.go
@@ -0,0 +1,30 @@
+package internal
+
+import (
+ "crypto/rand"
+ "os"
+ "time"
+)
+
+// Creates a random byteslice of `size`
+func MakeRandomByteSlice(size int) ([]byte, error) {
+ byteSlice := make([]byte, size)
+ _, err := rand.Read(byteSlice)
+ if err != nil {
+ return nil, err
+ }
+ return byteSlice, nil
+}
+
+func GenerateTimeSeconds() int64 {
+ current := time.Now()
+ return current.Unix()
+}
+
+func EnsureDirectory(directory string) error {
+ mkdirErr := os.MkdirAll(directory, os.ModePerm)
+ if mkdirErr != nil {
+ return mkdirErr
+ }
+ return nil
+}