Refactor Register Funktion

This commit is contained in:
hoernschen 2020-10-04 14:22:52 +02:00
parent c79d1f86e4
commit 7db9c374cc
5 changed files with 129 additions and 21 deletions

View file

@ -0,0 +1,42 @@
package utils
import (
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"fmt"
"log"
)
func CreateToken() (err error, token string) {
b := make([]byte, 8)
_, err = rand.Read(b)
if err != nil {
log.Fatal(err)
return
}
token = string(b)
return
}
func CreateUUID() (err error, uuid string) {
b := make([]byte, 16)
_, err = rand.Read(b)
if err != nil {
log.Fatal(err)
return
}
uuid = fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
return
}
func Hash(s []byte) (err error, hashString string) {
h := sha256.New()
_, err = h.Write(s)
if nil != err {
return
}
hash := h.Sum(nil)
hashString = base64.StdEncoding.EncodeToString(hash)
return
}

View file

@ -12,7 +12,7 @@ type ErrorResponse struct {
RetryTime int `json:"retry_after_ms,omitempty"`
}
func CheckRequest(r *http.Request, request interface{}) (response *ErrorResponse) {
func CheckRequest(r *http.Request) (response *ErrorResponse) {
if !strings.Contains(r.Header.Get("Content-Type"), "application/json") {
response = &ErrorResponse{ErrorMessage: "Content Type not JSON"}
}