etoken

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: MIT Imports: 8 Imported by: 0

README

egorm 组件使用指南

goproxy.cn Release Example

1 简介

针对jwt做了简单封装

2 使用方式

go get github.com/eezz10001/etoken

3 配置

type config struct {
    AccessTokenIss            string // JWT的签发者(iss)
    AccessTokenKey            string // JWT的加密密钥
    AccessTokenExpireInterval int64  // JWT到期时间(xp)
    TokenPrefix               string // token前缀名称,避免与数据库key冲突
}

4 用户配置

[token.test]
iss = "" # JWT的签发者(iss)
secret = "" # WT的加密密钥
expireInterval = "3600" # JWT过期时间(exp)
prefix = "/egotoken" # token前缀名称,避免与数据库key冲突

5 用户代码

配置创建一个 etoken 的配置项,其中内容按照上文配置进行填写。以上这个示例里这个配置key是token.test

代码中创建一个 etoken 实例 etoken.Load("key").Build(),代码中的 key 和配置中的 key 要保持一致。创建完 gorm 实例后,就可以直接使用他对 db 进行 crud

etoken.Load("token").Build(etoken.WithRedis(RedisStub))
etoken.CreateAccessToken(context.Background(),time.Now().Unix())

Documentation

Index

Constants

View Source
const PackageName = "component.etoken"

PackageName ..

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() *config

DefaultConfig ...

Types

type AccessTokenTicket

type AccessTokenTicket struct {
	AccessToken string `json:"accessToken"`
	ExpiresIn   int64  `json:"expiresIn"`
}

type Component

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

func (*Component) CheckAccessToken

func (c *Component) CheckAccessToken(ctx context.Context, tokenStr string) (flag bool, uid interface{}, err error)

func (*Component) CreateAccessToken

func (c *Component) CreateAccessToken(ctx context.Context, uid string, startTime int64) (resp AccessTokenTicket, err error)

func (*Component) DecodeAccessToken

func (c *Component) DecodeAccessToken(tokenStr string) (resp map[string]interface{}, err error)

func (*Component) EncodeAccessToken

func (c *Component) EncodeAccessToken(uid string, startTime int64) (tokenStr string, err error)

func (*Component) RefreshAccessToken

func (c *Component) RefreshAccessToken(ctx context.Context, tokenStr string, startTime int64) (resp AccessTokenTicket, err error)

type Container

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

func DefaultContainer

func DefaultContainer() *Container

func Load

func Load(key string) *Container

Load ...

func (*Container) Build

func (con *Container) Build(options ...Option) *Component

Build

type Option

type Option func(c *Container)

func WithLogger added in v0.0.4

func WithLogger(logger *elog.Component) Option

func WithRedis

func WithRedis(client *eredis.Component) Option

Jump to

Keyboard shortcuts

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