added globals

alpha v1.0.56
alex 2023-02-20 20:37:19 +01:00
parent 1284b74dfd
commit 6471f979c1
2 changed files with 51 additions and 4 deletions

View File

@ -1,14 +1,63 @@
package cnjglobals
import "github.com/gofiber/fiber/v2"
import (
"log"
"regexp"
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
)
const (
RequestHeaderXAuthorization = "X-Authorization"
LenUserId = 36
LenUserIdStr = "36" // same as LenUserId but as string
LenXAuthorizationHeader = 36 // used for api calls
LenSessionEncryptionKey = "32"
MinUsername = "2"
MaxUsername = "24"
MinAccountName = "4"
MaxAccountName = "24"
MinEmail = "3"
MaxEmail = "48"
MinPassword = "6"
MaxPassword = "64"
MinFcmToken = "116"
MaxFcmToken = "164"
AccountNameRegex = "^[a-zA-Z0-9_.]+$"
)
func init() {
log.Println("init test")
}
var (
GeneralRules = map[string]string{
"Username": "required,min=" + MinUsername + ",max=" + MaxUsername,
"AccountName": "required,min=" + MinAccountName + ",max=" + MaxAccountName + ",regexp=" + AccountNameRegex,
"Email": "required,email,min=" + MinEmail + ",max=" + MaxEmail,
"Password": "required", // password length is checked later because it is sent in base64 format
"UserId": "required,len=" + LenUserIdStr,
"TargetUserId": "required,len=" + LenUserIdStr,
"SessionEncryptionKey": "required,len=" + LenSessionEncryptionKey,
"Token": "required,min=" + MinFcmToken + ",max=" + MaxFcmToken, // fcm token
}
)
func RegexTag(fl validator.FieldLevel) bool {
field := fl.Field().String()
if field == "" {
return true
}
regexString := fl.Param()
regex := regexp.MustCompile(regexString)
match := regex.MatchString(field)
return match
}
func GetAuhorizationToken(c *fiber.Ctx) string {
return c.GetReqHeaders()[RequestHeaderXAuthorization]
}

View File

@ -24,8 +24,6 @@ const (
ContentTypeJson = "application/json"
SetQueueNameToAutomaticallyAssignedQueueName = "SetQueueNameToAutomaticallyAssignedQueueName"
Test123 = "test1234"
TestHaha = "testhaha"
)
type Config struct {