Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateAge(birthdate time.Time) int
- func Decrypt(key []byte, ciphertext string) (string, error)
- func DistanceInMeters(lat1, lon1, lat2, lon2 float64) float64
- func Encrypt(key []byte, plaintext string) (string, error)
- func GenerateRandomAlphanumeric(length int) string
- func GenerateRandomIndexes(max, count int) []int
- func GetAgeFromStringDate(dateStr string) (int, error)
- func GetRandomUniqueStrings(arr []string, count int) ([]string, error)
- func GetRemainingSecondsToday() time.Duration
- func IsNilOrZero(v any) bool
- func IsZero(v any) bool
- func List[T any](page int32, pageSize int32, list []T) (total, totalPage int64, res []T)
- func NewLog(config *LogsConfig) *zap.Logger
- func ParseInt(s string) int64
- func Random64(n int32) int64
- func RandomFloat(start float64, end float64) float64
- func RandomInt(min int, max int) int
- func StringPreIs(s string, prefix string) bool
- func StringToString(s string, split0 string, split1 string) string
- func ToSliceUint(s any, split string) ([]uint, error)
- func TruncateToTwoDecimal(num float64) float64
- func Validator(data any) error
- type Claims
- type Http
- func (h *Http) ClearDefaultHeaders() *Http
- func (h *Http) Do(urlPath string, method string, headers map[string]string, body io.Reader) ([]byte, error)
- func (h *Http) Get(params url.Values, result any) error
- func (h *Http) PostForm(formData url.Values, result any) error
- func (h *Http) PostJSON(jsonData any, result any) error
- func (h *Http) PostMultipart(formBuilder func(w *multipart.Writer) error, result any) error
- func (h *Http) SetHeader(key, value string) *Http
- func (h *Http) SetTimeout(timeout time.Duration) *Http
- type Jwt
- type JwtConfig
- type Log
- type LogsConfig
- type Request
- type Response
- func (r *Response) AuthError(err error)
- func (r *Response) Error(err error)
- func (r *Response) ErrorData(err error, data any)
- func (r *Response) ErrorMessage(message string)
- func (r *Response) LoginError(err error)
- func (r *Response) Response()
- func (r *Response) SetCode(code int)
- func (r *Response) SetData(data any)
- func (r *Response) SetMessage(message string)
- func (r *Response) Success(message string, data any)
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 DistanceInMeters ¶ added in v1.0.8
计算两个经纬度之间的距离(米)
func GetAgeFromStringDate ¶
GetAgeFromStringDate 从字符串日期直接计算年龄
func IsNilOrZero ¶ added in v1.0.8
func NewLog ¶ added in v1.0.8
func NewLog(config *LogsConfig) *zap.Logger
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 (*Http) ClearDefaultHeaders ¶ added in v1.0.8
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) PostMultipart ¶ added in v1.0.8
PostMultipart 发送 multipart/form-data 请求
type LogsConfig ¶ added in v1.0.8
type LogsConfig struct {
Debug *lumberjack.Logger
Info *lumberjack.Logger
Err *lumberjack.Logger
}
type Request ¶
func NewRequest ¶
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) ErrorMessage ¶
func (*Response) LoginError ¶
func (*Response) SetMessage ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.