Documentation
¶
Index ¶
- Constants
- Variables
- func Auth(ctx *context.Context) models.UserModel
- func Check(password string, username string) (user models.UserModel, ok bool)
- func CheckPermissions(user models.UserModel, path string, method string) bool
- func DelCookie(ctx *context.Context) bool
- func EncodePassword(pwd []byte) string
- func Filter(ctx *context.Context) (models.UserModel, bool, bool)
- func GetCurUser(sesKey string) (user models.UserModel, ok bool)
- func GetCurUserByID(id int64) (user models.UserModel, ok bool)
- func GetSessionByKey(sesKey, key string) interface{}
- func GetUserID(sesKey string) int64
- func SetCookie(ctx *context.Context, user models.UserModel) bool
- type CSRFToken
- type Config
- type DBDriver
- type Invoker
- type MiddlewareCallback
- type PersistenceDriver
- type Session
Constants ¶
const DefaultCookieKey = "go_admin_session"
Variables ¶
var ( // TokenHelper helps check the token. TokenHelper = new(CSRFToken) // CsrfTokenLock is the a lock of checking. CsrfTokenLock sync.Mutex )
var Middleware = DefaultInvoker().Middleware()
Middleware is the default auth middleware of plugins.
Functions ¶
func CheckPermissions ¶
CheckPermissions check the permission of the user.
func Filter ¶
Filter retrieve the user model from Context and check the permission at the same time.
func GetCurUser ¶ added in v1.0.9
GetCurUser return the user model.
func GetCurUserByID ¶ added in v1.0.8
GetCurUserByID return the user model of given user id.
func GetSessionByKey ¶ added in v1.0.9
func GetSessionByKey(sesKey, key string) interface{}
GetSessionByKey get the session value by key.
Types ¶
type CSRFToken ¶
type CSRFToken []string
CSRFToken is type of a csrf token list.
func (*CSRFToken) CheckToken ¶
CheckToken check the given token with tokens in the CSRFToken, if exist return true.
type DBDriver ¶ added in v1.0.8
type DBDriver struct{}
DBDriver is a driver which uses database as a persistence tool.
var Driver DBDriver
Driver is the default PersistenceDriver.
type Invoker ¶
type Invoker struct {
// contains filtered or unexported fields
}
Invoker contains the callback functions which are used in the route middleware.
func DefaultInvoker ¶ added in v1.0.0
func DefaultInvoker() *Invoker
DefaultInvoker return a default Invoker.
func (*Invoker) Middleware ¶
Middleware get the auth middleware from Invoker.
func (*Invoker) SetAuthFailCallback ¶
func (invoker *Invoker) SetAuthFailCallback(callback MiddlewareCallback) *Invoker
SetAuthFailCallback set the authFailCallback of Invoker.
func (*Invoker) SetPermissionDenyCallback ¶
func (invoker *Invoker) SetPermissionDenyCallback(callback MiddlewareCallback) *Invoker
SetPermissionDenyCallback set the permissionDenyCallback of Invoker.
type MiddlewareCallback ¶
MiddlewareCallback is type of callback function.
type PersistenceDriver ¶
type PersistenceDriver interface {
Load(string) map[string]interface{}
Update(sid string, values map[string]interface{})
}
PersistenceDriver is a driver of storing and getting the session info.
type Session ¶
type Session struct {
Expires time.Duration
Cookie string
Values map[string]interface{}
Driver PersistenceDriver
Sid string
Context *context.Context
}
Session contains info of session.
func InitSession ¶
InitSession return the default Session.
func (*Session) UpdateConfig ¶
UpdateConfig update the Expires and Cookie of Session.
func (*Session) UseDriver ¶ added in v1.0.8
func (ses *Session) UseDriver(driver PersistenceDriver)
UseDriver set the driver of the Session.