本文整理匯總了Golang中github.com/opesun/nocrud/frame/interfaces.User.Level方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.Level方法的具體用法?Golang User.Level怎麽用?Golang User.Level使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/opesun/nocrud/frame/interfaces.User
的用法示例。
在下文中一共展示了User.Level方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (h *HighLev) Run(db iface.Db, usr iface.User, defminlev int) ([]interface{}, error) {
desc := h.desc
levi, ok := jsonp.Get(h.nouns, fmt.Sprintf("%v.verbs.%v.level", desc.Sentence.Noun, desc.Sentence.Verb))
if !ok {
levi = defminlev
}
lev, _ := numcon.Int(levi)
if usr.Level() < lev {
return nil, fmt.Errorf("Not allowed.")
}
filterCreator := func(c string, input map[string]interface{}) (iface.Filter, error) {
return db.NewFilter(c, input)
}
inp, data, err := desc.CreateInputs(filterCreator)
if err != nil {
return nil, err
}
if data != nil {
if desc.Sentence.Noun != "options" {
data, err = h.validate(desc.Sentence.Noun, desc.Sentence.Verb, data)
if err != nil {
return nil, err
}
}
inp = append(inp, data)
}
module := h.hooks.Module(desc.VerbLocation)
if !module.Exists() {
return nil, fmt.Errorf("Unkown module.")
}
ins := module.Instance()
var ret []interface{}
ret_rec := func(i ...interface{}) {
ret = i
}
err = ins.Method(desc.Sentence.Verb).Call(ret_rec, inp...)
if err != nil {
return nil, err
}
return ret, nil
}
示例2: NotAdmin
func NotAdmin(user iface.User) bool {
return user.Level() < 300
}
示例3: Run
func (h *HighLev) Run(db iface.Db, usr iface.User, defminlev int) ([]interface{}, error) {
desc := h.desc
// Authentication.
levi, ok := jsonp.Get(h.nouns, fmt.Sprintf("%v.verbs.%v.level", desc.Sentence.Noun, desc.Sentence.Verb))
if !ok {
levi = defminlev
}
lev, _ := numcon.Int(levi)
if usr.Level() < lev {
return nil, fmt.Errorf("Not allowed.")
}
err := h.userChecks(usr)
if err != nil {
return nil, err
}
filterCreator := func(c string, input map[string]interface{}) (iface.Filter, error) {
return db.NewFilter(c, input)
}
inp, data, err := desc.CreateInputs(filterCreator)
if err != nil {
return nil, err
}
ownLev, own := h.ownLev()
if len(inp) > 0 {
if f, ok := inp[0].(iface.Filter); ok {
// This hook allows you to modify a filter before a verb accesses it.
h.hooks.Select("TopModFilter").Fire(f)
h.hooks.Select(f.Subject() + "TopModFilter").Fire(f)
}
if own && lev <= ownLev {
if f, ok := inp[0].(iface.Filter); ok {
f.AddQuery(map[string]interface{}{
"createdBy": usr.Id(),
})
}
}
}
if data != nil {
if desc.Sentence.Noun != "options" {
data, err = h.validate(desc.Sentence.Noun, desc.Sentence.Verb, data)
if err != nil {
return nil, err
}
}
inp = append(inp, data)
}
module := h.hooks.Module(desc.VerbLocation)
if !module.Exists() {
return nil, fmt.Errorf("Unkown module.")
}
ins := module.Instance()
var ret []interface{}
ret_rec := func(i ...interface{}) {
ret = i
}
err = ins.Method(desc.Sentence.Verb).Call(ret_rec, inp...)
if err != nil {
return nil, err
}
return ret, nil
}
示例4: OnlyAdmin
func OnlyAdmin(u iface.User) {
if u.Level() < 300 {
panic("Only an admin can do this operation.")
}
}
示例5: IsStranger
func IsStranger(user iface.User) bool {
return user.Level() == 0
}
示例6: IsRegistered
func IsRegistered(user iface.User) bool {
return user.Level() >= 100
}
示例7: IsModerator
func IsModerator(user iface.User) bool {
return user.Level() >= 200
}
示例8: IsAdmin
func IsAdmin(user iface.User) bool {
return user.Level() >= 300
}