redistoken

package module
v0.0.0-...-9967f23 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

redistoken

A simple authorization with redis middleware for flygo

Usage


//Create new app
app := flygo.NewApp()

//Create RedisAuth

app := flygo.NewApp()

redisToken := New().Options(&redis.Options{
    Addr:     "192.168.1.8:6379",
    Password: "123",
    DB:       0,
})

app.Use(redisToken)

app.Run()

Config

  • Set redis key prefix for stored token
redistoken.Key(KEY)
  • Set redis apps key
redistoken.AppKey(APPKEY)
  • Set redis key expires
redistoken.Expires(EXPIRES)
  • Set token length
redistoken.Length(LENGTH)
  • Set msg
redistoken.Msg(MSG)
  • Set code
redistoken.Code(CODE)

Documentation

Index

Constants

View Source
const (
	//The redis key prefix
	RedisKey = "auth:authorization"

	//The redis apps key prefix
	RedisAppsKey = "auth:apps"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisToken

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

Define RedisToken struct

func New

func New() *RedisToken

Return new RedisToken

func (*RedisToken) AppKey

func (r *RedisToken) AppKey(appKey string) *RedisToken

Set app key prefix for redis

func (*RedisToken) Code

func (r *RedisToken) Code(code int) *RedisToken

Set return code when unauthorized

func (*RedisToken) Expires

func (r *RedisToken) Expires(expires time.Duration) *RedisToken

Set expires

func (*RedisToken) Fields

func (r *RedisToken) Fields() []*flygo.Field

Set middleware fields

func (*RedisToken) Key

func (r *RedisToken) Key(key string) *RedisToken

Set key prefix for redis

func (*RedisToken) Length

func (r *RedisToken) Length(length int) *RedisToken

Set length

func (*RedisToken) Method

func (r *RedisToken) Method() string

Set middleware global method

func (*RedisToken) Msg

func (r *RedisToken) Msg(msg string) *RedisToken

Set return msg when unauthorized

func (*RedisToken) Name

func (*RedisToken) Name() string

Set middleware name

func (*RedisToken) Options

func (r *RedisToken) Options(options *redis.Options) *RedisToken

Set redis options

func (*RedisToken) Pattern

func (r *RedisToken) Pattern() string

Set middleware global pattern

func (*RedisToken) Process

func (r *RedisToken) Process() flygo.Handler

Set middleware process

Jump to

Keyboard shortcuts

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