goweb

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const EarthRadiusMeters = 6371000.0

地球平均半径(米)

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 DistanceInMeters added in v1.0.8

func DistanceInMeters(lat1, lon1, lat2, lon2 float64) float64

计算两个经纬度之间的距离(米)

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 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 IsNilOrZero added in v1.0.8

func IsNilOrZero(v any) bool

func IsZero added in v1.0.8

func IsZero(v any) bool

func List added in v1.0.8

func List[T any](page int32, pageSize int32, list []T) (total, totalPage int64, res []T)

List 数据做分页

func NewLog added in v1.0.8

func NewLog(config *LogsConfig) *zap.Logger

func ParseInt

func ParseInt(s string) int64

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

func Random64 added in v1.0.8

func Random64(n int32) int64

*

  • @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 Http added in v1.0.8

type Http struct {
	Url    string // 存储基础URL
	Client *http.Client
	// contains filtered or unexported fields
}

func NewHttp added in v1.0.8

func NewHttp(url string) *Http

func (*Http) ClearDefaultHeaders added in v1.0.8

func (h *Http) ClearDefaultHeaders() *Http

ClearDefaultHeaders 清除默认请求头

func (*Http) Do added in v1.0.8

func (h *Http) Do(urlPath string, method string, headers map[string]string, body io.Reader) ([]byte, error)

Do 执行HTTP请求

func (*Http) Get added in v1.0.8

func (h *Http) Get(params url.Values, result any) error

Get 执行GET请求

func (*Http) PostForm added in v1.0.8

func (h *Http) PostForm(formData url.Values, result any) error

PostForm 发送表单数据

func (*Http) PostJSON added in v1.0.8

func (h *Http) PostJSON(jsonData any, result any) error

PostJSON 发送JSON数据

func (*Http) PostMultipart added in v1.0.8

func (h *Http) PostMultipart(formBuilder func(w *multipart.Writer) error, result any) error

PostMultipart 发送 multipart/form-data 请求

func (*Http) SetHeader added in v1.0.8

func (h *Http) SetHeader(key, value string) *Http

SetDefaultHeader 设置默认请求头

func (*Http) SetTimeout added in v1.0.8

func (h *Http) SetTimeout(timeout time.Duration) *Http

SetTimeout 设置超时时间

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
	Sign   string
}

type Log added in v1.0.8

type Log struct {
}

type LogsConfig added in v1.0.8

type LogsConfig struct {
	Debug *lumberjack.Logger
	Info  *lumberjack.Logger
	Err   *lumberjack.Logger
}

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) ErrorData added in v1.0.8

func (r *Response) ErrorData(err error, data any)

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
log module
sdk
ali

Jump to

Keyboard shortcuts

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