utilo

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 24 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     = errors.New("Token is expired")
	TokenNotValidYet = errors.New("Token not active yet")
	TokenMalformed   = errors.New("That's not even a token")
	TokenInvalid     = errors.New("Couldn't handle this token:")
)

Functions

func BcryptCheck

func BcryptCheck(password, hash string) bool

BcryptCheck 对比明文密码和数据库的哈希值

func BcryptHash

func BcryptHash(password string) string

BcryptHash 使用 bcrypt 对密码进行加密

func BuildPubKey

func BuildPubKey(pubKey string) (*rsa.PublicKey, error)

BuildPubKey 构建公钥

func Contains

func Contains[T comparable](slice []T, element T) bool

func Convert2Float32

func Convert2Float32(str string, dv float32) float32

func ConvertPrt2Ids

func ConvertPrt2Ids(str *string) []int64

func ConvertString2Ids

func ConvertString2Ids(str string) []int64

func DecodeJwt

func DecodeJwt(jwt string) (*modelo.CustomClaims, error)

func DecodePayload

func DecodePayload(payload string) (*modelo.CustomClaims, error)

func Format

func Format[T *time.Time | time.Time](t T, format ...string) string

Format 此时直接出入 nil 会报错

func Format1 deprecated

func Format1(t *time.Time) string

Deprecated: Format

func FormatV0 deprecated

func FormatV0(t *time.Time) string

Deprecated: Format

func FormatVal deprecated

func FormatVal(t time.Time) string

Deprecated: Format

func GenRsaCertPair

func GenRsaCertPair()

func GenerateOrderSN

func GenerateOrderSN(memberId int64) string

func GenerateRefundSN

func GenerateRefundSN(orderID, orderItemID int64) string

func GenerateUid

func GenerateUid() string

GenerateUid generates a UUIDv7 and retries up to 10 times in case of error.

func JonIds

func JonIds(ids []int64, sp string) string

func MD5V

func MD5V(str []byte, b ...byte) string

MD5V @function: MD5V @description: md5加密 @param: str []byte @return: string

func Marshal

func Marshal(val any) (map[string]map[string]any, error)

Marshal marshals the given val and returns the map that contains the fields. optional=another is not implemented, and it's hard to implement and not common used.

func MustParse

func MustParse(tStr string) time.Time

func Parse

func Parse(tStr string) (time.Time, error)

func ReadAsNestedMap

func ReadAsNestedMap[T Numeric](filePath string, separator rune, fn func(v string, dv T) T, dv T) (map[string]map[string]T, error)

ReadAsNestedMap 读取CSV文件并返回嵌套的Map

func ReadPriKey deprecated

func ReadPriKey(keyPath string) (*rsa.PrivateKey, error)

Deprecated: ReadPriKeyOfAbPath 相对路径

func ReadPriKeyOfAbPath

func ReadPriKeyOfAbPath(abPath string) (*rsa.PrivateKey, error)

ReadPriKeyOfAbPath 绝对路径

func ReadPubKey deprecated

func ReadPubKey(keyPath string) (*rsa.PublicKey, error)

Deprecated: ReadPubKeyOfAbPath 读取公钥(相对路径)

func ReadPubKeyOfAbPath

func ReadPubKeyOfAbPath(abPath string) (*rsa.PublicKey, error)

ReadPubKeyOfAbPath 读取公钥(绝对路径)

func RemoveBearer

func RemoveBearer(token string) string

RemoveBearer remove token Bearer prefix if necessary

func Shuffle

func Shuffle[T any](s []T)

func ToPrt

func ToPrt[T any](i T) *T

func ToVl

func ToVl[T any](i *T) T

ToVl 返回指针i指向的值,如果i是nil,则返回T的零值。

func TryParse

func TryParse(tStr string) time.Time

Types

type JWTParser

type JWTParser struct {
	SigningKey *rsa.PublicKey
}

func GetParser deprecated

func GetParser(path string) (*JWTParser, error)

Deprecated: GetParserOfAbPath(相对路径)

func GetParserFromKey

func GetParserFromKey(pubKey string) (*JWTParser, error)

func GetParserOfAbPath

func GetParserOfAbPath(abPath string) (*JWTParser, error)

func (*JWTParser) ParseToken

func (j *JWTParser) ParseToken(tokenString string) (*modelo.CustomClaims, error)

ParseToken 解析 token

type Numeric

type Numeric interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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