parent
1284b74dfd
commit
6471f979c1
|
@ -1,14 +1,63 @@
|
||||||
package cnjglobals
|
package cnjglobals
|
||||||
|
|
||||||
import "github.com/gofiber/fiber/v2"
|
import (
|
||||||
|
"log"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RequestHeaderXAuthorization = "X-Authorization"
|
RequestHeaderXAuthorization = "X-Authorization"
|
||||||
|
|
||||||
LenUserId = 36
|
LenUserId = 36
|
||||||
LenXAuthorizationHeader = 36 // used for api calls
|
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 {
|
func GetAuhorizationToken(c *fiber.Ctx) string {
|
||||||
return c.GetReqHeaders()[RequestHeaderXAuthorization]
|
return c.GetReqHeaders()[RequestHeaderXAuthorization]
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,6 @@ const (
|
||||||
ContentTypeJson = "application/json"
|
ContentTypeJson = "application/json"
|
||||||
|
|
||||||
SetQueueNameToAutomaticallyAssignedQueueName = "SetQueueNameToAutomaticallyAssignedQueueName"
|
SetQueueNameToAutomaticallyAssignedQueueName = "SetQueueNameToAutomaticallyAssignedQueueName"
|
||||||
Test123 = "test1234"
|
|
||||||
TestHaha = "testhaha"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|
Loading…
Reference in New Issue