utils

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VersionEqual = iota
	VersionGreater
	VersionLess
)
View Source
const (
	UA = `` /* 135-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func CompVersion added in v0.2.4

func CompVersion(v1, v2 string) (int, error)

func Crypto added in v0.3.1

func Crypto(v []byte, key []byte) ([]byte, error)

func CryptoToBase64 added in v0.3.1

func CryptoToBase64(v []byte, key []byte) (string, error)

func Decrypto added in v0.3.1

func Decrypto(v []byte, key []byte) ([]byte, error)

func DecryptoFromBase64 added in v0.3.1

func DecryptoFromBase64(v string, key []byte) ([]byte, error)

func Exists

func Exists(name string) bool

func ForceColor added in v0.3.1

func ForceColor() bool

func GenCryptoKey added in v0.3.1

func GenCryptoKey(base string) []byte

func GenCryptoKeyWithBytes added in v0.3.1

func GenCryptoKeyWithBytes(base []byte) []byte

func GetEnvFiles added in v0.4.2

func GetEnvFiles(root string) ([]string, error)

func GetFileExtension added in v0.5.2

func GetFileExtension(f string) string

func GetPageAndMax added in v0.3.1

func GetPageAndMax(ctx *gin.Context) (page int, max int, err error)

func GetPageItems

func GetPageItems[T any](items []T, page, pageSize int) []T

func GetPageItemsRange added in v0.3.0

func GetPageItemsRange(total, page, pageSize int) (start, end int)

func GetUrlExtension added in v0.3.0

func GetUrlExtension(u string) string

func HttpCookieToMap added in v0.3.0

func HttpCookieToMap(c []*http.Cookie) map[string]string

func In

func In[T comparable](items []T, item T) bool

func Index

func Index[T comparable](items []T, item T) int

func IsLocalIP added in v0.3.0

func IsLocalIP(address string) bool

func LIKE added in v0.3.0

func LIKE(s string) string

func MapToHttpCookie added in v0.3.0

func MapToHttpCookie(m map[string]string) []*http.Cookie

func NoRedirectHttpClient added in v0.3.0

func NoRedirectHttpClient() *http.Client

func OptFilePath added in v0.3.0

func OptFilePath(filePath string) (string, error)

func ParseURLIsLocalIP added in v0.3.0

func ParseURLIsLocalIP(u string) (bool, error)

func RandBytes

func RandBytes(n int) []byte

func RandString

func RandString(n int) string

func ReadYaml

func ReadYaml(file string, module any) error

func SortUUID added in v0.3.0

func SortUUID() string

func SortUUIDWithUUID added in v0.3.2

func SortUUIDWithUUID(src uuid.UUID) string

func SplitVersion added in v0.2.4

func SplitVersion(v string) ([]int, error)

func TruncateByRune added in v0.3.5

func TruncateByRune(s string, length int) string

func WriteYaml

func WriteYaml(file string, module any) error

Types

type Once added in v0.3.0

type Once struct {
	// contains filtered or unexported fields
}

func (*Once) Do added in v0.3.0

func (o *Once) Do(f func())

func (*Once) Done added in v0.3.0

func (o *Once) Done() (doned bool)

func (*Once) Reset added in v0.3.0

func (o *Once) Reset()

type UpgraderConf

type UpgraderConf func(*websocket.Upgrader)

func WithSubprotocols

func WithSubprotocols(Subprotocols []string) UpgraderConf

type WebSocket

type WebSocket struct {
	Heartbeat time.Duration
}

func DefaultWebSocket

func DefaultWebSocket() *WebSocket

func NewWebSocketServer

func NewWebSocketServer(conf ...WebSocketConfig) *WebSocket

func (*WebSocket) NewWebSocketClient

func (ws *WebSocket) NewWebSocketClient(w http.ResponseWriter, r *http.Request, responseHeader http.Header, conf ...UpgraderConf) (*websocket.Conn, error)

func (*WebSocket) Server

func (ws *WebSocket) Server(w http.ResponseWriter, r *http.Request, Subprotocols []string, handler func(c *websocket.Conn) error) error

type WebSocketConfig

type WebSocketConfig func(*WebSocket)

func WithHeartbeatInterval

func WithHeartbeatInterval(d time.Duration) WebSocketConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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