moved util functions in main.go into a seperate file

This commit is contained in:
2021-01-14 22:14:11 +01:00
parent d788822b06
commit 41583afb47
3 changed files with 22 additions and 17 deletions

View File

@ -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".

View File

@ -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)
}

21
src/util.go Normal file
View File

@ -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)
}