util

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateDayFormat = "20060102"
)

Variables

This section is empty.

Functions

func BoolToInt

func BoolToInt(value bool) int

func DateNumber

func DateNumber() string

func EscapeHtml

func EscapeHtml(value string) string

func FindAddress added in v1.0.0

func FindAddress(ctx context.Context, ip string) (string, error)

func FormatDatetime

func FormatDatetime(timestamp int64) string

func GenFileName

func GenFileName(ext string) string

func GenImageName

func GenImageName(ext string, width, height int) string

随机生成指定后缀的图片名

func GenValidateCode

func GenValidateCode(length int) string

生成数字验证码

func GenerateId

func GenerateId() string

func HttpDownloadFile

func HttpDownloadFile(ctx context.Context, fileURL string, proxyURL ...string) []byte

func HttpGet

func HttpGet(ctx context.Context, url string, header map[string]string, data g.Map, result interface{}, proxyURL ...string) error

func HttpPost

func HttpPost(ctx context.Context, url string, header map[string]string, data, result interface{}, proxyURL ...string) error

func HttpPostJson added in v1.1.0

func HttpPostJson(ctx context.Context, url string, header map[string]string, data, result interface{}, proxyURL ...string) error

func IsDateFormat

func IsDateFormat(date string) bool

func Location

func Location() *time.Location

func NewMsgId

func NewMsgId() string

func NewSecretKey added in v1.1.0

func NewSecretKey(userId, length int, prefix ...string) string

func ParseHtmlImage

func ParseHtmlImage(text string) string

ParseHtmlImage 解析 Md 文本中的图片信息

func ParseHtmlImageAll

func ParseHtmlImageAll(text string) []string

ParseHtmlImageAll 解析 Md 文本中的所有图片信息

func ParseIds

func ParseIds(str string) []int

func Random

func Random(length int) string

生成随机字符串

func RenderTemplate

func RenderTemplate(data any) (string, error)

func ReplaceImgAll

func ReplaceImgAll(value string) string

func Retry

func Retry(num int, sleep time.Duration, fn func() error) error

func Strip

func Strip(s string) string

Strip returns the given string sans any Markdown. Where necessary, elements are replaced with their best textual forms, so for example, hyperlinks are stripped of their URL and become only the link text, and images lose their URL and become only the alt text.

func ToMap

func ToMap[T any, K int | string](arr []T, fn func(T) K) map[K]T

切片转 map

func Unique

func Unique[T IntInterface | string](data []T) []T

切片去重

func WebSocketClient

func WebSocketClient(ctx context.Context, wsURL string, messageType int, message []byte, result chan []byte, proxyURL ...string) (*websocket.Conn, error)

func WebSocketClientOnlyReceive

func WebSocketClientOnlyReceive(ctx context.Context, wsURL string, result chan []byte, proxyURL ...string) (*websocket.Conn, error)

Types

type ImageInfo

type ImageInfo struct {
	Md5Sum   string
	FilePath string
	Size     int
	Width    int
	Height   int
}

func SaveImage

func SaveImage(ctx context.Context, imgBytes []byte, ext string, fileName ...string) (*ImageInfo, error)

type ImageMeta

type ImageMeta struct {
	Width  int
	Height int
}

func ReadImageMeta

func ReadImageMeta(r io.Reader) *ImageMeta

ReadImageMeta 读取图片媒体信息

type IntInterface

type IntInterface interface {
	uint | uint8 | uint16 | uint32 | uint64 | int | int8 | int16 | int32 | int64
}

type IpAddressResponse added in v1.0.0

type IpAddressResponse struct {
	Code   string `json:"resultcode"`
	Reason string `json:"reason"`
	Result struct {
		Country  string `json:"Country"`
		Province string `json:"Province"`
		City     string `json:"City"`
		Isp      string `json:"Isp"`
	} `json:"result"`
	ErrorCode int `json:"error_code"`
}

type RoundRobin added in v1.0.0

type RoundRobin struct {
	CurIndex int
}

func (*RoundRobin) RoundRobin added in v1.0.0

func (roundRobin *RoundRobin) RoundRobin(values []string) (value string)

轮询模式

Jump to

Keyboard shortcuts

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