utils

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrMsgArg  = "plz input arg:{%s}"
	ErrMsgFlag = "plz input flag:{%s}"
)

Variables

View Source
var HideHelpCommand func(c []*cli.Command)

Functions

func AnsiStrip

func AnsiStrip(str string) string

func ArgOrPipe added in v0.1.6

func ArgOrPipe(args string) (string, error)

ArgOrPipe -

func CalcPermutation

func CalcPermutation(n, r int) int

func CalcPermutationMore

func CalcPermutationMore(n, r1, r2 int) int

func ContainsItems

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

ContainsItems checks if s1 contains s2

func CopyFile added in v0.1.7

func CopyFile(dest, src string) error

Copy file from [src] to [dest] by little buffer

func Dedupe

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

Dedupe removes duplicates from a slice of elements preserving the order

func GenerateAlphabet added in v0.1.9

func GenerateAlphabet(regex string) []byte

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 GetArgFilePipe added in v0.1.6

func GetArgFilePipe(arg string) ([]byte, error)

GetArgFilePipe Get arg from c.Arg > File > Pipe

func GetFileBytes added in v0.1.6

func GetFileBytes(path string) ([]byte, error)

func GetFileOrPipe added in v0.1.6

func GetFileOrPipe(args []string) ([]byte, error)

func GetFileString added in v0.1.6

func GetFileString(path string) (string, error)

func GetFirstArg added in v0.1.6

func GetFirstArg(args []string) (string, error)

GetFirstArg -

func GetFromPipe added in v0.1.6

func GetFromPipe() ([]byte, error)

func GetHeaderToken

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

func Intersection

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

func OutputBytes added in v0.1.6

func OutputBytes(s []byte) error

OutputBytes -

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 RandomBytesByLength added in v0.1.6

func RandomBytesByLength[T constraints.Integer](n T, regex ...string) []byte

RandomBytesByLength 随机字符串

func RandomString

func RandomString() string

RandomString 随机字符串

func RandomStringByLength

func RandomStringByLength[T constraints.Integer](n T, regex ...string) 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 TableOutput added in v0.1.6

func TableOutput(datas [][]*simpletable.Cell, header, footer []*simpletable.Cell) string

func ValidArg added in v0.1.6

func ValidArg(field interface{}, tag string) error

func ValidFlag added in v0.1.6

func ValidFlag(field interface{}, tag string) error

func Validator added in v0.1.6

func Validator(field interface{}, tag string, errMsg string) error

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.RegisteredClaims
}

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