Documentation ¶
Overview ¶
rbac := middleware.NewRbac() m.Map(rbac) m.Get("/article/edit", func(c *middleware.Context, rbac *middleware.Rbac) { ok := rbac.IsGranted("editor", "edit.article", func(role, permission string, rbac *middleware.Rbac) bool { return article.Owner == User.Id }) if ok { fmt.Println("have permission....") } else { fmt.Println("not have permission....") } c.HTML(200, "index", c.Data) })
Index ¶
- Constants
- Variables
- func AuthRequest(disUrls ...string) martini.Handler
- func EncodeMsg(msg Msg) (body []byte, err error)
- func I18n(options ...I18nOptions) martini.Handler
- func InitContext() martini.Handler
- func InitContextNoSess() martini.Handler
- func InitSession(name, key string) martini.Handler
- func Tr(format string, args ...interface{}) string
- func Version() string
- type AssertionFunc
- type Context
- func (self *Context) AddMessage(message string)
- func (self *Context) Clear()
- func (self *Context) ClearMessages()
- func (self *Context) Delete(key string)
- func (self *Context) Get(key string) interface{}
- func (self *Context) GetSession(name string, value interface{}) (err error)
- func (self *Context) HMessage(code int, url, message string, v ...interface{})
- func (self *Context) HTML(code int, name string, binding interface{}, htmlOpt ...HTMLOptions)
- func (self *Context) HasMessage() bool
- func (self *Context) JMessage(code int, url, message string, v ...interface{})
- func (self *Context) PostForm(key string, def ...string) (value string)
- func (self *Context) Query(key string, def ...string) (value string)
- func (self *Context) Set(key string, val interface{})
- type HTMLOptions
- type I18nOptions
- type Map
- type Msg
- type Rbac
- func (rbac *Rbac) Add(name string, permissions []string, parents []string)
- func (rbac *Rbac) Dump() Map
- func (rbac *Rbac) Get(name string) Role
- func (rbac *Rbac) IsGranted(name, permission string, assert AssertionFunc) bool
- func (rbac *Rbac) Remove(name string)
- func (rbac *Rbac) Set(name string, permissions []string, parents []string)
- type Role
- type RoleFactoryFunc
- type RoleMap
Constants ¶
const ( ParentKey = "parents" PermissionKey = "permissions" NameKey = "name" )
Variables ¶
var Locale *i18n.Locale
Functions ¶
func AuthRequest ¶
setup not need check authorize URL
urls := []string{"/login", "/users", "/firewall"} m.Use(middleware.AuthRequest(urls...))
func I18n ¶
func I18n(options ...I18nOptions) martini.Handler
I18n is a middleware provides localization layer for your application. Paramenter langs must be in the form of "en-US", "zh-CN", etc. Otherwise it may not recognize browser input.
func InitContext ¶
func InitContextNoSess ¶
func InitSession ¶
Types ¶
type AssertionFunc ¶
Assertion function supplies more fine-grained permission controls.
type Context ¶
type Context struct { render.Render C martini.Context P martini.Params S sessions.Session R *http.Request W http.ResponseWriter FormErr binding.Errors Messages []string Errors []string Data map[string]interface{} // contains filtered or unexported fields }
func (*Context) AddMessage ¶
func (*Context) ClearMessages ¶
func (self *Context) ClearMessages()
func (*Context) GetSession ¶
Parse session value
func (*Context) HTML ¶
func (self *Context) HTML(code int, name string, binding interface{}, htmlOpt ...HTMLOptions)
Parse HTML code
func (*Context) HasMessage ¶
type HTMLOptions ¶
type I18nOptions ¶
type I18nOptions struct { Domain string Directory string ZipData []byte DefaultLang string // Suburl of path. Default is empty. SubURL string CookieName string // Name of language parameter name in URL. Default is "lang". Parameter string // Redirect when user uses get parameter to specify language. Redirect bool // Name that maps into template variable. Default is "i18n". TmplName string Inited bool }
Options represents a struct for specifying configuration options for the i18n middleware.
type Msg ¶
type Rbac ¶
type Rbac struct {
// contains filtered or unexported fields
}
RBAC
func NewRbac ¶
func NewRbac() *Rbac
Return a RBAC structure. The default role structure will be used.
func NewWithFactory ¶
func NewWithFactory(factory RoleFactoryFunc) *Rbac
Return a RBAC structure with a specific factory function. Role structure will be generated by the function.
func RestoreWithFactory ¶
func RestoreWithFactory(data Map, factory RoleFactoryFunc) *Rbac
Restore rbac from a map, use factory for your own data structure
func (*Rbac) Add ¶
Add a role with `name`. It has `permissions` and `parents`. If the role is not existing, a new one will be created. This function will add new permissions and parents to the role, and keep orignals.
type Role ¶
type Role interface { Name() string AddPermission(string) HasPermission(string) bool RevokePermission(string) Permissions() []string AddParent(string) RemoveParent(string) Parents() []string Reset() }
Implement this interface for your own role structure.
type RoleFactoryFunc ¶
Sometimes, a custom role structure is needed by projects. You should define your own role factory function for this purpuse.