token

package
v0.0.0-...-ee0865d Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIllegal 错误-令牌非法
	ErrIllegal = errors.New("token illegal")
	// ErrExpired 错误-令牌过期
	ErrExpired = errors.New("token expired")
	// ErrUseNotMatch 错误-令牌的用途不匹配
	ErrUseNotMatch = errors.New("token use notmatch")
)

Functions

func Create

func Create(info *Info, hmacSampleSecret string) (t string)

CreateLater 令牌-创建

func GetRemoteIP

func GetRemoteIP(ctx context.Context) (ip string)

GetRemoteIP 获取ctx的remote ip

func GetUid

func GetUid(ctx context.Context) (uid int)

GetUid 获取ctx的uid

func ToOutgoing

func ToOutgoing(ctx context.Context) context.Context

Types

type ContextKey

type ContextKey string

ContextKey 上下文的Key

const (
	// ContextKeyRemote 客户端地址
	ContextKeyRemote ContextKey = "remote"
	// ContextKeyUid 用户id
	ContextKeyUid ContextKey = "uid"
)

type Info

type Info struct {
	// 用户id
	Uid int64
	// token的用途
	Use Use
}

TargetInfo 令牌信息

func Valid

func Valid(token string, use Use, hmacSecret string, expired int) (val *Info, err error)

Valid 验证token

type Use

type Use int

Use token的用途

const (
	// UseUnknown 未知
	UseUnknown Use = iota
	// UseLogin 用于登录
	UseLogin
)

Jump to

Keyboard shortcuts

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