From 41583afb475f7dc230d579a6deab09ca29ec1212 Mon Sep 17 00:00:00 2001 From: MrGeorgen Date: Thu, 14 Jan 2021 22:14:11 +0100 Subject: [PATCH] moved util functions in main.go into a seperate file --- README.md | 2 +- src/main.go | 16 ---------------- src/util.go | 21 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 src/util.go diff --git a/README.md b/README.md index f47a29d..e8a61f3 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,4 @@ RBU account system # api use `/login?redirect=someurl` to redirect the user after the login is finnished. Use `api/accountinfo?accountkey=key&password=password` to get information about the user. -accountKey is the value of the cookie with the key "session". +accountkey is the value of the cookie with the key "session". diff --git a/src/main.go b/src/main.go index 30c4d5d..e79b55f 100644 --- a/src/main.go +++ b/src/main.go @@ -9,12 +9,10 @@ import ( "github.com/zaddok/moodle" "html/template" "io/ioutil" - "net/http" "os" "regexp" "code.gitea.io/sdk/gitea" "fmt" - "golang.org/x/crypto/argon2" ) var discord *discordgo.Session var secret secrets_json @@ -86,17 +84,3 @@ func main() { http.ListenAndServe(":" + fmt.Sprint(config.Port), nil) } -func log(err error) { - if err!=nil { - panic(err) - } -} - -func hashFunc(password []byte, salt []byte) []byte { - return argon2.IDKey(password, salt, 1, 64*1024, 4, 32) -} -func runTemplate(w http.ResponseWriter, template *template.Template, templateData interface{}) { - w.Header().Set("Content-Type", "text/html") - var err error = template.Execute(w, templateData) - log(err) -} diff --git a/src/util.go b/src/util.go new file mode 100644 index 0000000..5f11dce --- /dev/null +++ b/src/util.go @@ -0,0 +1,21 @@ +package main +import ( + "golang.org/x/crypto/argon2" + "net/http" + "html/template" +) + +func log(err error) { + if err!=nil { + panic(err) + } +} + +func hashFunc(password []byte, salt []byte) []byte { + return argon2.IDKey(password, salt, 1, 64*1024, 4, 32) +} +func runTemplate(w http.ResponseWriter, template *template.Template, templateData interface{}) { + w.Header().Set("Content-Type", "text/html") + var err error = template.Execute(w, templateData) + log(err) +}