redisauth

package module
v0.0.0-...-6e60c71 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: 4 Imported by: 0

README

redisauth

A simple authentication with redis middleware for flygo

Usage


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

//Create RedisAuth
redisAuth := New().Options(&redis.Options{
    Addr:     "192.168.1.8:6379",
    Password: "123",
    DB:       0,
}).Rule(NewRule(ModeInclude, []string{
    "/index/**",
})).Source(NewSource(SourceParameter, Authorization))

//Use RedisAuth
app.UseInterceptor(redisAuth)

//Bind `/`
app.Get("/", func(c flygo.Context) {
    c.Text("index")
})

//Bind `/index/aaa`
app.Get("/index/aaa", func(c flygo.Context) {
    ad := c.GetParameter(AuthorizationData)
    c.Text("ad = " + ad)
})

//Run
app.Run()

Rule Config

  • Include Mode
NewRule(ModeInclude, []string{
    "/**",
})
  • Exclude Mode
NewRule(ModeExclude, []string{
    "/exclude/**",
})

Source Config

  • Parameter

    The middleware will get named Authorization val in request parameters

NewSource(SourceParameter, "Authorization")
  • Header

    The middleware will get named Authorization val in request headers

NewSource(SourceHeader, "Authorization")

Get AuthorizationData

c.GetMiddlewareData(redisAuth.Name(), AuthorizationData)

Documentation

Index

Constants

View Source
const (
	//The parameter name
	Authorization = "Authorization"

	//Authorization passed
	//The Redis value in parameter
	AuthorizationData = "AuthorizationData"

	//The redis key prefix
	RedisKey = "auth:authorization:"
)
View Source
const (
	ModeInclude = iota
	ModeExclude
)

Define Mode const

View Source
const (
	SourceParameter = iota
	SourceHeader
)

Define Source const

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisAuth

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

Define RedisAuth struct

func New

func New() *RedisAuth

Return new RedisAuth

func (*RedisAuth) Code

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

Set return code when unauthorized

func (*RedisAuth) Key

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

Set key prefix for redis

func (*RedisAuth) Msg

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

Set return msg when unauthorized

func (*RedisAuth) Name

func (*RedisAuth) Name() string

Set middleware name

func (*RedisAuth) Options

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

Set redis options

func (*RedisAuth) Pattern

func (r *RedisAuth) Pattern() string

Set middleware global pattern

func (*RedisAuth) Process

func (r *RedisAuth) Process() flygo.InterceptorHandler

Set middleware process

func (*RedisAuth) Rule

func (r *RedisAuth) Rule(rule Rule) *RedisAuth

Set validate rule

func (*RedisAuth) Source

func (r *RedisAuth) Source(source Source) *RedisAuth

Set source

func (*RedisAuth) Type

func (*RedisAuth) Type() string

Set middleware type

type Rule

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

Define Rule struct

func NewRule

func NewRule(mode int, patterns []string) Rule

Return new Rule

type Source

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

Define Source struct

func NewSource

func NewSource(source int, name string) Source

Return new Source

Jump to

Keyboard shortcuts

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