goweb

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Rules = map[string]string{
	"custom":                "",
	"required":              "^.+$",
	"alpha":                 "^[a-zA-Z]+$",
	"num":                   "^-?[0-9]+$",
	"float":                 "^(-?\\d+)(\\.\\d+)?$",
	"varName":               "^[a-zA-Z][\\w]*$",
	"alphaNum":              "^[a-zA-Z0-9]+$",
	"alphaNumUnline":        "^[\\w]+$",
	"alphaNumUnlineDash":    "^[\\w\\-]+$",
	"chs":                   "^[\u4e00-\u9fa5]+$",
	"chsAlpha":              "^[a-zA-Z\u4e00-\u9fa5]+$",
	"chsAlphaNum":           "^[a-zA-Z0-9\u4e00-\u9fa5]+$",
	"chsAlphaNumUnline":     "^[\\w\u4e00-\u9fa5]+$",
	"chsAlphaNumUnlineDash": "^[\\w\\-\u4e00-\u9fa5]+$",
	"mobile":                "^1\\d{10}$",
	"email":                 "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$",
	"postalCode":            "^[1-9]\\d{5}$",
	"idCard":                "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)",
	"ip":                    "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}",
	"website":               "https?://([\\S]+)\\.([\\S]+)",
	"between":               "",
	"equal":                 "",
	"in":                    "",
	"len":                   "",
}

Functions

func CalculateAge

func CalculateAge(birthdate time.Time) int

CalculateAge 计算年龄

func Decrypt

func Decrypt(key []byte, ciphertext string) (string, error)

解密函数 - 使用AES-GCM模式

func Encrypt

func Encrypt(key []byte, plaintext string) (string, error)

加密函数 - 使用AES-GCM模式

func GenerateRandomAlphanumeric

func GenerateRandomAlphanumeric(length int) string

*

  • @description:生成随机字符串

func GenerateRandomIndexes

func GenerateRandomIndexes(max, count int) []int

生成不重复的随机索引

func Get

func Get(apiUrl string, params url.Values, res any) error

get网络请求

func GetAgeFromStringDate

func GetAgeFromStringDate(dateStr string) (int, error)

GetAgeFromStringDate 从字符串日期直接计算年龄

func GetRandomUniqueStrings

func GetRandomUniqueStrings(arr []string, count int) ([]string, error)

*

  • @description:从数组中随机获取count个元素(不重复)组成新数组

func GetRemainingSecondsToday

func GetRemainingSecondsToday() time.Duration

获取今天剩余时间

func ParseInt

func ParseInt(s string) int64

ParseInt 处理字符串,返回其整数部分,非数字则返回0

func Post

func Post(apiUrl string, params url.Values, res any) error

post网络请求

func Random

func Random(n int32) int32

*

  • @description: 生成指定位数随机整数
  • @param {int32} n 位数

func RandomFloat

func RandomFloat(start float64, end float64) float64

*

  • @description: 生成随机数,指定范围
  • @param {int} min 最小值,包含
  • @param {int} max 最大值,不包含

func RandomInt

func RandomInt(min int, max int) int

*

  • @description: 生成随机数,指定范围
  • @param {int} min 最小值,包含
  • @param {int} max 最大值,不包含

func StringPreIs

func StringPreIs(s string, prefix string) bool

*

  • @description:判断字符串是否以prefix开头

func StringToString

func StringToString(s string, split0 string, split1 string) string

*

  • @description:字符串转字符串,例如1,2,3转成1','2','3

func ToSliceUint

func ToSliceUint(s any, split string) ([]uint, error)

*

  • @description:字符串转切片,例如1,2,3转成[]uint{1,2,3}

func TruncateToTwoDecimal

func TruncateToTwoDecimal(num float64) float64

*

  • @description: 保留两位浮点数小数

func Validator

func Validator(data any) error

验证数据

Types

type Claims

type Claims struct {
	ID   int32  `json:"id"`
	Type string `json:"type"`
	jwt.RegisteredClaims
}

type Jwt

type Jwt struct {
	Config *JwtConfig
}

func NewJwt

func NewJwt(cfg *JwtConfig) *Jwt

func (*Jwt) Get

func (j *Jwt) Get(t string, claims *Claims) error

func (*Jwt) Set

func (j *Jwt) Set(id int32, types string) (string, error)

type JwtConfig

type JwtConfig struct {
	Expir  int64 // jwt登录过期时间,分钟,1440一天
	Issuer string
}

type Request

type Request struct {
	Param any
	Error error
}

func NewRequest

func NewRequest(param any) *Request

func (*Request) Bind

func (r *Request) Bind(req *http.Request) *Request

func (*Request) Validate

func (r *Request) Validate() *Request

type Response

type Response struct {
	Message string              `json:"message"`
	Code    int                 `json:"code"`
	Data    any                 `json:"data"`
	Writer  http.ResponseWriter `json:"-"`
}

func NewResponse

func NewResponse(w http.ResponseWriter) *Response

func (*Response) AuthError

func (r *Response) AuthError(err error)

func (*Response) Error

func (r *Response) Error(err error)

func (*Response) ErrorMessage

func (r *Response) ErrorMessage(message string)

func (*Response) LoginError

func (r *Response) LoginError(err error)

func (*Response) Response

func (r *Response) Response()

func (*Response) SetCode

func (r *Response) SetCode(code int)

func (*Response) SetData

func (r *Response) SetData(data any)

func (*Response) SetMessage

func (r *Response) SetMessage(message string)

func (*Response) Success

func (r *Response) Success(message string, data any)

Directories

Path Synopsis
sdk
ali

Jump to

Keyboard shortcuts

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