Score
0
Watch 3 Star 4 Fork 0

flygotm / redisauthGoApache-2.0

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
A simple authentication with redis middleware for flygo spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

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)

Comments ( 0 )

Sign in for post a comment

Go
1
https://gitee.com/flygotm/redisauth.git
git@gitee.com:flygotm/redisauth.git
flygotm
redisauth
redisauth
master

Search