utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHost = fmt.Errorf("cannot parse host")
)

Error

Functions

func AnsiStrip

func AnsiStrip(str string) string

func CalcPermutation

func CalcPermutation(n, r int) int

func CalcPermutationMore

func CalcPermutationMore(n, r1, r2 int) int

func CheckPort

func CheckPort(port int) error

CheckPort -

func ContainsItems

func ContainsItems[T comparable](s1 []T, s2 []T) bool

ContainsItems checks if s1 contains s2

func Dedupe

func Dedupe[T comparable](inputSlice []T) (result []T)

Dedupe removes duplicates from a slice of elements preserving the order

func GeneratePassword

func GeneratePassword(password string) string

GeneratePassword - Generate bcrypt hash password

func GenerateToken

func GenerateToken(token, username string) (string, error)

GenerateToken generate tokens used for auth

func GetHeaderToken

func GetHeaderToken(authorization string) (token string, err error)

func Intersection

func Intersection[T comparable](s1, s2 []T) []T

func ParseAddr

func ParseAddr(addr string) (string, int, error)

ParseAddr -

func ParseHost

func ParseHost(host string) (ips []string)

ParseHost 解析 Host 地址

func ParsePort

func ParsePort(portStr string) (ports []int)

ParsePort 解析端口

func ParseURLToHostAndURI

func ParseURLToHostAndURI(u string) (string, string, error)

ParseURLToHostAndURI [http/s://]domain/ip[:port]/uri -> host,uri,err

func PickRandom

func PickRandom[T any](v []T) T

PickRandom item from a slice of elements

func PruneEmptyStrings

func PruneEmptyStrings(v []string) []string

PruneEmptyStrings from the slice

func PruneEqual

func PruneEqual[T comparable](inputSlice []T, equalTo T) (r []T)

PruneEqual removes items from the slice equal to the specified value

func RandomString

func RandomString() string

RandomString 随机字符串

func RandomStringByLength

func RandomStringByLength(n int, allowedChars ...[]rune) string

RandomStringByLength 随机字符串

func RefreshToken

func RefreshToken(tokenString string) (string, error)

RefreshToken -

func SliceContains

func SliceContains[T comparable](inputSlice []T, element T) bool

SliceContains if a slice contains an element

func SliceToInt

func SliceToInt(s []string) ([]int, error)

ToInt converts a slice of strings to a slice of ints

func VerifyPassword

func VerifyPassword(hash, password string) bool

VerifyPassword - Verify bcrypt hash password

Types

type Claims

type Claims struct {
	Token    string `json:"token"`
	Username string `json:"username"`
	jwt.StandardClaims
}

Claims -

func ParseToken

func ParseToken(token string) (*Claims, error)

ParseToken parsing token

type OncePlus

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

func (*OncePlus) Do

func (o *OncePlus) Do(f func() error) error

func (*OncePlus) SlowDo

func (o *OncePlus) SlowDo(f func() error) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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