Documentation
¶
Index ¶
- Variables
- func AuthorizeMiddleware(authorizer Authorizer, unauthorizedAction http.HandlerFunc) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func AuthorizeOrForbiddenMiddleware(authorizer Authorizer) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func LoginRequiredMiddleware(identifier Identifier, unauthorizedAction http.HandlerFunc) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func LogoutMiddleware(s LogoutProvider) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func MiddlewareForbiddenExceptForUsers(identifier Identifier, users []string) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- type Account
- type AccountProvider
- type Accounts
- type Authorizer
- type Identifier
- type LoginProvider
- type LoginRedirector
- func (lr *LoginRedirector) ClearSource(w http.ResponseWriter, r *http.Request) (string, error)
- func (lr *LoginRedirector) Middleware(s Identifier) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func (lr *LoginRedirector) MustClearSource(w http.ResponseWriter, r *http.Request) string
- func (lr *LoginRedirector) RedirectAction(w http.ResponseWriter, r *http.Request)
- type LogoutProvider
- type PlainAccountProvider
- type Redirector
- func (r *Redirector) ClearSource(w http.ResponseWriter, req *http.Request) (string, error)
- func (r *Redirector) Middleware() func(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
- func (r *Redirector) MustClearSource(w http.ResponseWriter, req *http.Request) string
- func (r *Redirector) RedirectAction(w http.ResponseWriter, req *http.Request)
Constants ¶
This section is empty.
Variables ¶
var CaseInsensitiveAcountProvider = &PlainAccountProvider{ Prefix: "", CaseInsensitive: true, }
CaseInsensitiveAcountProvider plain account provider which case insensitive
var CaseSensitiveAcountProvider = &PlainAccountProvider{ Prefix: "", CaseInsensitive: false, }
CaseSensitiveAcountProvider plain account provider which case sensitive
var ErrAccountBindingExists = errors.New("account binding exists")
ErrAccountBindingExists error rasied when account exists when binding
var ErrAccountUnbindingNotExists = errors.New("account unbinding dose not exist")
ErrAccountUnbindingNotExists error rasied when account does not exist when unbinding
Functions ¶
func AuthorizeMiddleware ¶
func AuthorizeMiddleware(authorizer Authorizer, unauthorizedAction http.HandlerFunc) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
AuthorizeMiddleware middleware which authorize http request with authorizer. Params unauthorizedAction will be executed if authorize fail. If authorize fail and params unauthorizedAction is nil,http error 403 will be execute.
func AuthorizeOrForbiddenMiddleware ¶
func AuthorizeOrForbiddenMiddleware(authorizer Authorizer) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
AuthorizeOrForbiddenMiddleware middleware which authorize http request with authorizer. http error 403 will be executed if authorize fail.
func LoginRequiredMiddleware ¶
func LoginRequiredMiddleware(identifier Identifier, unauthorizedAction http.HandlerFunc) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
LoginRequiredMiddleware middleware which indentify user with identifier. If indentify fail param unauthorizedAction will be executed.
func LogoutMiddleware ¶
func LogoutMiddleware(s LogoutProvider) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
LogoutMiddleware middleware which will logout user.
func MiddlewareForbiddenExceptForUsers ¶
func MiddlewareForbiddenExceptForUsers(identifier Identifier, users []string) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
MiddlewareForbiddenExceptForUsers middleware which identify user with identifier,and return http 403 error if user is not in users list.
Types ¶
type AccountProvider ¶
type AccountProvider interface {
//NewAccount create new account with keyword and account
NewAccount(keyword string, account string) (*Account, error)
}
AccountProvider account provider interface
type Accounts ¶
type Accounts []*Account
Accounts type account list
func (*Accounts) Bind ¶
Bind add account to accountlist. Return any error if raised. If account exists in account list,error ErrAccountBindingExists will be raised.
type Authorizer ¶
type Authorizer interface {
//Authorize authorize http request.
//Return authorize result and any error raised.
Authorize(*http.Request) (bool, error)
}
Authorizer user role authorizer interface
type Identifier ¶
type Identifier interface {
//IdentifyRequest identify http request
//return identification and any error if rasied.
IdentifyRequest(r *http.Request) (string, error)
}
Identifier http request identifier
type LoginProvider ¶
LoginProvider Login provider interface
type LoginRedirector ¶
type LoginRedirector struct {
//LoginURL redirector will redirect user to this url if user didnot log in.
LoginURL string
//Cookie cookie settings.
Cookie *http.Cookie
}
LoginRedirector login redirector struct
func NewLoginRedirector ¶
func NewLoginRedirector(loginurl string, cookiename string) *LoginRedirector
NewLoginRedirector create new login redirector with given login url and cookie name.
func (*LoginRedirector) ClearSource ¶
func (lr *LoginRedirector) ClearSource(w http.ResponseWriter, r *http.Request) (string, error)
ClearSource return and clear the url before redirect. Return url and any error if raised.
func (*LoginRedirector) Middleware ¶
func (lr *LoginRedirector) Middleware(s Identifier) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
Middleware redirector middleware
func (*LoginRedirector) MustClearSource ¶
func (lr *LoginRedirector) MustClearSource(w http.ResponseWriter, r *http.Request) string
MustClearSource return and clear the url before redirect.
func (*LoginRedirector) RedirectAction ¶
func (lr *LoginRedirector) RedirectAction(w http.ResponseWriter, r *http.Request)
RedirectAction action which set cookie and redirect user.
type LogoutProvider ¶
type LogoutProvider interface {
Logout(w http.ResponseWriter, r *http.Request) error
}
LogoutProvider Logout provider interface
type PlainAccountProvider ¶
PlainAccountProvider plain account provider.
func (*PlainAccountProvider) NewAccount ¶
func (p *PlainAccountProvider) NewAccount(keyword string, account string) (*Account, error)
NewAccount create new account is CaseInsensitive is true,account name will be convert to lower
type Redirector ¶
type Redirector struct {
TargetURL string
Cookie *http.Cookie
Condition func(w http.ResponseWriter, req *http.Request) bool
}
Redirector redirector request when condition is true.
func NewRedirector ¶
func NewRedirector(url string, cookiename string, condition func(w http.ResponseWriter, req *http.Request) bool) *Redirector
NewRedirector create new redirector wotj govem cookie name and condition
func (*Redirector) ClearSource ¶
func (r *Redirector) ClearSource(w http.ResponseWriter, req *http.Request) (string, error)
ClearSource return and clear the url before redirect. Return url and any error if raised.
func (*Redirector) Middleware ¶
func (r *Redirector) Middleware() func(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
Middleware redirector middleware
func (*Redirector) MustClearSource ¶
func (r *Redirector) MustClearSource(w http.ResponseWriter, req *http.Request) string
MustClearSource return and clear the url before redirect.
func (*Redirector) RedirectAction ¶
func (r *Redirector) RedirectAction(w http.ResponseWriter, req *http.Request)
RedirectAction redirect action of redirector