servicebase

package
v0.0.0-...-8051343 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MessageSuccess          = "Success"
	MessageInternalError    = "Internal server error"
	MessageFailedDecodeJSON = "Failed to decode JSON"
	MessagePasswordInvalid  = "Minimum eight characters, at least one uppercase letter, one lowercase letter, one number, and one special character"
)
View Source
var (
	PasswordValidation = `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$`
	MinAge             = 18
)
View Source
var (
	CodeSuccess = "BE-000"
	Code4XX     = "BE-4XX"
	Code5XX     = "BE-5XX"
)
View Source
var CalculateAge = func(birthdate time.Time) int {
	now := time.Now()
	age := now.Year() - birthdate.Year()

	if now.YearDay() < birthdate.YearDay() {
		age--
	}

	return age
}
View Source
var (
	ID_LANG = "id"
)
View Source
var MustAbove18Rule = func(birthdate, layout string) bool {
	birthdateTime, err := time.Parse(layout, birthdate)
	if err != nil {
		return false
	}

	age := CalculateAge(birthdateTime)

	return age >= MinAge
}
View Source
var PasswordValidationRule = validation.NewStringRule(func(s string) bool {
	if len(s) < 8 {
		return false
	}

	var hasUpper, hasLower, hasSpecial bool
	for _, char := range s {
		switch {
		case unicode.IsUpper(char):
			hasUpper = true
		case unicode.IsLower(char):
			hasLower = true
		case unicode.IsPunct(char) || unicode.IsSymbol(char):
			hasSpecial = true
		}
	}

	return hasUpper && hasLower && hasSpecial
}, MessagePasswordInvalid)

Functions

func Translate

func Translate(lang string)

Types

type Pagination

type Pagination struct {
	Limit      int `json:"limit"`
	Page       int `json:"page"`
	TotalPages int `json:"totalPages"`
	Records    int `json:"records"`
}

type ResponseBody

type ResponseBody struct {
	Code       string      `json:"code"`
	Message    string      `json:"message"`
	Pagination *Pagination `json:"pagination,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL