httputil

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxUsernameLength  = 20
	MinUsernameLength  = 3
	MaxNicknameLength  = 20
	MinNicknameLength  = 2
	MaxGroupnameLength = 20
	MinGroupnameLength = 2
	MaxPasswordLength  = 20
	MinPasswordLength  = 6
)
View Source
const (
	PasswordUpper int = 1 << iota
	PasswordLower
	PasswordDigit
	PasswordSpecial
)

1大写,2小写,4数字,8符号

View Source
const PasswordSpecialLetter = "!@#$%^&."

Variables

This section is empty.

Functions

func Bad

func Bad(w http.ResponseWriter, params ...any)

Bad 错误的请求

func BadError

func BadError(w http.ResponseWriter, status int, data any, params ...any)

BadError 返回错误信息

func BadW

func BadW(w http.ResponseWriter, msg string) error

BadW 返回错误信息

func Forbidden

func Forbidden(w http.ResponseWriter, err any)

Forbidden Forbidden

func GetClientIP

func GetClientIP(r *http.Request) string

func GetOrigin

func GetOrigin(r *http.Request) string

GetOrigin 获取客户端origin

func GetUserAgent

func GetUserAgent(r *http.Request) useragent.UserAgent

func IsEmail

func IsEmail(email string) bool

IsEmail 验证邮箱

func IsGroupName

func IsGroupName(nickname string) bool

IsGroupName 部门名称 长度2-20个UTF-8字符 可使用除了禁止输入字符之外的任意字符

func IsHash

func IsHash(s string) bool

IsHash 是否是有效的hash

func IsIncludeForbiddenChar

func IsIncludeForbiddenChar(value string) bool

IsIncludeForbiddenChar 是否包含禁用字符,空格 ; 分号 -- 连续的减号 " " 引号 { } 大括号 [ ] 中括号 ( ) 小括号

func IsLessEndTime

func IsLessEndTime(fl validator.FieldLevel) bool

func IsLessThanNow

func IsLessThanNow(fl validator.FieldLevel) bool

IsLessThanNow 检查时间小于当前时间戳

func IsMobile

func IsMobile(mobile string) bool

IsMobile 识别手机号码

func IsMoreThanNow

func IsMoreThanNow(fl validator.FieldLevel) bool

IsMoreThanNow 检查时间大于当前时间戳

func IsNickname

func IsNickname(nickname string) bool

IsNickname 姓名 长度2-20个UTF-8字符 可使用除了禁止输入字符之外的任意字符

func IsPassword

func IsPassword(password string, chains ...func(string) bool) bool

IsPassword 1. 设置密码规则有,最小长度默认最小长度6个字符,字符不能小于6个,默认最大密码长度(20) 2. 设置包含:大写字母、小写字母、数字和字符(默认都不开启) 3. 开启限制后,用户注册必须按照规范注册用户 4. 已经注册过的用户,登录时不按照密码规则校验 5. 密码特殊字符包括: !@#$%^&. 6. 默认密码不开启验证时,密码必须属于写字母、小写字母、数字和字符中一种或多种组合

func IsPasswordSpecialLetter

func IsPasswordSpecialLetter(r rune) bool

func IsUserName

func IsUserName(username string) bool

IsUserName 用户名检查

func MapStructDecode

func MapStructDecode(input interface{}, output interface{}) error

MapStructDecode takes an input structure and uses reflection to translate it to the output structure. output must be a pointer to a map or struct.

func Ok

func Ok(w http.ResponseWriter, params ...any)

Ok 返回成功信息, params作为动态参数,默认没有参数则返回204

func OkList

func OkList(w http.ResponseWriter, list any, total int64)

OkList 返回成功列表

func SetContext

func SetContext(r *http.Request, key string, value any) *http.Request

func SetFieldMap

func SetFieldMap(t map[string]string)

func SetTagMap

func SetTagMap(t map[string]string)

func ShouldJson

func ShouldJson(r *http.Request, obj any) error

func UidGet

func UidGet(r *http.Request) int64

func UidSet

func UidSet(r *http.Request, uid int64) *http.Request

func ValidateStruct

func ValidateStruct(obj any) error

ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.

Types

type JsonDataBody

type JsonDataBody struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data,omitempty"`
}

JsonDataBody json响应体

type JsonListBody

type JsonListBody struct {
	List  any    `json:"list"`
	Total int64  `json:"total"`
	Code  int    `json:"code,omitempty"`
	Msg   string `json:"msg,omitempty"`
}

JsonListBody 分页响应体

type JsonRawBody

type JsonRawBody map[string]any

type SliceValidationError

type SliceValidationError []error

func (SliceValidationError) Error

func (err SliceValidationError) Error() string

Error concatenates all error elements in SliceValidationError into a single string separated by \n.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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