diff options
author | FChannel <> | 2022-05-05 10:05:40 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | af542e339e5a611d2a1b5876450bee841b577640 (patch) | |
tree | 987f4fce83d49605a0a81d68fcfac9b2d57cf8a7 /util/key.go | |
parent | 493fc8e025fd613d9faf0b573d610e4a0e0c0228 (diff) |
removed redis dependency
Diffstat (limited to 'util/key.go')
-rw-r--r-- | util/key.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/util/key.go b/util/key.go index 458d7c0..cd8662a 100644 --- a/util/key.go +++ b/util/key.go @@ -4,7 +4,11 @@ import ( "crypto/sha512" "encoding/hex" "math/rand" + "os" "strings" + + "github.com/FChannel0/FChannel-Server/config" + "github.com/gofiber/fiber/v2/middleware/encryptcookie" ) const domain = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -34,3 +38,21 @@ func RandomID(size int) string { return newID.String() } + +func GetCookieKey() (string, error) { + if config.CookieKey == "" { + var file *os.File + var err error + + if file, err = os.OpenFile("config/config-init", os.O_APPEND|os.O_WRONLY, 0644); err != nil { + return "", err + } + + defer file.Close() + + config.CookieKey = encryptcookie.GenerateKey() + file.WriteString("cookiekey:" + config.CookieKey) + } + + return config.CookieKey, nil +} |