initial commit
This commit is contained in:
21
vendor/github.com/labstack/echo-contrib/LICENSE
generated
vendored
Normal file
21
vendor/github.com/labstack/echo-contrib/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 LabStack
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
65
vendor/github.com/labstack/echo-contrib/session/session.go
generated
vendored
Normal file
65
vendor/github.com/labstack/echo-contrib/session/session.go
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/labstack/echo"
|
||||
"github.com/labstack/echo/middleware"
|
||||
)
|
||||
|
||||
type (
|
||||
// Config defines the config for CasbinAuth middleware.
|
||||
Config struct {
|
||||
// Skipper defines a function to skip middleware.
|
||||
Skipper middleware.Skipper
|
||||
|
||||
// Session store.
|
||||
// Required.
|
||||
Store sessions.Store
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
key = "_session_store"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultConfig is the default Session middleware config.
|
||||
DefaultConfig = Config{
|
||||
Skipper: middleware.DefaultSkipper,
|
||||
}
|
||||
)
|
||||
|
||||
// Get returns a named session.
|
||||
func Get(name string, c echo.Context) (*sessions.Session, error) {
|
||||
store := c.Get(key).(sessions.Store)
|
||||
return store.Get(c.Request(), name)
|
||||
}
|
||||
|
||||
// Middleware returns a Session middleware.
|
||||
func Middleware(store sessions.Store) echo.MiddlewareFunc {
|
||||
c := DefaultConfig
|
||||
c.Store = store
|
||||
return MiddlewareWithConfig(c)
|
||||
}
|
||||
|
||||
// MiddlewareWithConfig returns a Sessions middleware with config.
|
||||
// See `Middleware()`.
|
||||
func MiddlewareWithConfig(config Config) echo.MiddlewareFunc {
|
||||
// Defaults
|
||||
if config.Skipper == nil {
|
||||
config.Skipper = DefaultConfig.Skipper
|
||||
}
|
||||
if config.Store == nil {
|
||||
panic("echo: session middleware requires store")
|
||||
}
|
||||
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
if config.Skipper(c) {
|
||||
return next(c)
|
||||
}
|
||||
c.Set(key, config.Store)
|
||||
return next(c)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user