utils

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultJwtSecret = "607510af2d25158d055686c7"
	DefaultJwtExpSec = 60 * 60 * 24
)

Variables

View Source
var DefaultJwtAlg = jwt.SigningMethodHS256
View Source
var DefaultJwtOptions = SimpleJwtOptions{
	TokenJwtExpSec: 60 * 60 * 30,
	TokenJwtAlg:    "HS256",
	TokenJwtSecret: "123456789",
}
View Source
var SimJwtToken = &SimpleJwtToken{}

Functions

func AuthorMd5Decode

func AuthorMd5Decode(ak, userId string, nickname string, avatarUrl, accessKey string, secret string) error

AuthorMd5Decode 验证数据签名

func AuthorMd5Encode

func AuthorMd5Encode(author *CrossAppAuthor, secret string, expire time.Duration) (string, error)

AuthorMd5Encode md5 密钥签名

func Base64Decode

func Base64Decode(base64Str string) (string, error)

Base64Decode base64解码

func Base64Encode

func Base64Encode(str string) string

Base64Encode base64编码

func DecodeURLComponent

func DecodeURLComponent(str string) string

DecodeURLComponent url解码

func EncodeURIComponent

func EncodeURIComponent(str string) string

EncodeURIComponent url编码

func FilterStrSlice

func FilterStrSlice(items []string, filter StrSliceFilter) []string

FilterStrSlice 过滤字符串数组

func FilterStrSliceDuplicate

func FilterStrSliceDuplicate(items []string, filter StrSliceFilter) []string

FilterStrSliceDuplicate 去掉重复项,并按filter过滤返回结果

func Iff

func Iff(express bool, trueValue, failValue interface{}) interface{}

Iff 三目运算

func JsonDecode

func JsonDecode(jsonStr string, result interface{}) error

JsonDecode json解码

func JsonEncode

func JsonEncode(value interface{}) (string, error)

JsonEncode json编码

func JsonTryEncode

func JsonTryEncode(value interface{}) string

JsonTryEncode json编码,忽略error

func Md5

func Md5(s string) string

Md5 md5加密

func NewTokenJwtAlg

func NewTokenJwtAlg(name string) jwt.SigningMethod

func ParseUrlQuery

func ParseUrlQuery(urlQuery string) map[string]any

ParseUrlQuery 解析url参数

func SafeCall

func SafeCall(entry func())

func SliceFilter

func SliceFilter[T any](rows []T, comparer func(v T, idx ...int) bool) []T

func SliceFind

func SliceFind[T any](rows []T, comparer func(v T, idx ...int) bool) *T

SliceFind 在slice中查找某一项

func SliceFindIndex

func SliceFindIndex[T any](rows []T, comparer func(v T, idx ...int) bool) int

SliceFindIndex 在slice中查找索引序号,不存在时返回-1

func StrReplaceSearch added in v0.0.4

func StrReplaceSearch(str string, startStr, endStr string, replace SubReplacer) string

func StrSliceFilterEmpty

func StrSliceFilterEmpty(rows *[]string) *[]string

func StrSliceIndexOf added in v0.0.5

func StrSliceIndexOf(items []string, substr string) int

func StrVal

func StrVal(value interface{}) string

StrVal 获取变量的字符串值 浮点型 3.0将会转换成字符串3, "3" 非数值或字符类型的变量将会被转换成JSON格式字符串

Types

type BaseAuthor

type BaseAuthor interface {
	GetUserId() string
	GetNickname() string
}

type CrossAppAuthor

type CrossAppAuthor struct {
	AK string `json:"ak"`
	SimpleBaseAuthor
	AvatarUrl string `json:"avatarUrl"`
}

type JwtTarget

type JwtTarget struct {
	Issuer  string `json:"issuer"`
	Subject string `json:"subject"`
}

func (*JwtTarget) String

func (jt *JwtTarget) String() string

type JwtToken

type JwtToken interface {
	EncodeJwtToken(author BaseAuthor, target *JwtTarget, tokenSecret ...string) (string, error)
	DecodeJwtToken(tokenStr string, author BaseAuthor, tokenSecret ...string) (BaseAuthor, *JwtTarget, error)
}

func NewJwtToken

func NewJwtToken(options *JwtTokenOptions) JwtToken

type JwtTokenOptions

type JwtTokenOptions struct {
	TokenJwtSecret string            `json:"tokenJwtSecret"`
	TokenJwtExp    time.Duration     `json:"tokenJwtExp"`
	TokenJwtAlg    jwt.SigningMethod `json:"tokenJwtAlg"`
}

type SimpleBaseAuthor

type SimpleBaseAuthor struct {
	UserId   string `json:"userId"`
	NickName string `json:"nickName"`
}

func (*SimpleBaseAuthor) GetNickname

func (s *SimpleBaseAuthor) GetNickname() string

func (*SimpleBaseAuthor) GetUserId

func (s *SimpleBaseAuthor) GetUserId() string

type SimpleJwtOptions added in v0.0.5

type SimpleJwtOptions struct {
	TokenJwtExpSec time.Duration
	TokenJwtAlg    string
	TokenJwtSecret string
}

type SimpleJwtToken added in v0.0.5

type SimpleJwtToken struct {
}

func (*SimpleJwtToken) Decode added in v0.0.5

func (jt *SimpleJwtToken) Decode(tokenStr string, opts *SimpleJwtOptions) (interface{}, *JwtTarget, error)

Decode 验证token

func (*SimpleJwtToken) Encode added in v0.0.5

func (jt *SimpleJwtToken) Encode(payload interface{}, target *JwtTarget, opts *SimpleJwtOptions) (string, error)

Encode 生成token

type SimpleTokenPayload added in v0.0.5

type SimpleTokenPayload struct {
	Payload interface{} `json:"payload"`
	jwt.StandardClaims
}

type StrScanner added in v0.0.4

type StrScanner interface {
	Next() bool
	Prev() bool
	Read(readLen int) string
	ReadRune() *rune
	Current() int
	Inc(step int)
	Dec(step int)
}

func NewStrScanner added in v0.0.4

func NewStrScanner(str string) StrScanner

type StrSliceFilter

type StrSliceFilter func(s string) bool

type SubReplacer added in v0.0.4

type SubReplacer func(sub string) string

type SubStrIndex added in v0.0.4

type SubStrIndex struct {
	Sub      string
	StartIdx int
	EndIdx   int
}

func StrSearchSubs added in v0.0.4

func StrSearchSubs(str string, startStr, endStr string) []*SubStrIndex

func (*SubStrIndex) String added in v0.0.4

func (si *SubStrIndex) String() string

type TokenPayload

type TokenPayload struct {
	Payload BaseAuthor `json:"payload"`
	jwt.StandardClaims
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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