本文整理汇总了Golang中github.com/opesun/jsonp.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TypeConfig
// Both everyone and personal.
func (v *V) TypeConfig() error {
uni := v.uni
typ := uni.Req.Form["type"][0]
op, ok := jsonp.Get(uni.Opt, "Modules.content.types."+typ)
if !ok {
return fmt.Errorf("Can not find content type " + typ + " in options.")
}
uni.Dat["type"] = typ
uni.Dat["type_options"], _ = json.MarshalIndent(op, "", " ")
uni.Dat["op"] = op
user_type_op, _ := jsonp.Get(uni.Dat["_user"], "content_options."+typ)
uni.Dat["user_type_op"] = user_type_op
return nil
}
示例2: AD
func AD(uni *context.Uni) error {
defer adErr(uni)
var err error
if lev, k := jsonp.Get(uni.Dat, "_user.level"); k == false || lev.(int) < 300 {
if admin_model.SiteHasAdmin(uni.Db) {
uni.Dat["_points"] = []string{"admin/login"}
} else {
uni.Dat["_points"] = []string{"admin/regfirstadmin"}
}
return nil
}
m, cerr := routep.Comp("/admin/{modname}", uni.P)
if cerr != nil { // It should be always nil anyway.
return fmt.Errorf("Control is routed to Admin display, but it does not like the url structure.")
}
modname, _ := m["modname"]
switch modname {
case "":
err = Index(uni)
case "edit-config":
err = EditConfig(uni)
case "install":
err = Install(uni)
case "uninstall":
err = Uninstall(uni)
default:
_, installed := jsonp.Get(uni.Opt, "Modules."+modname)
if !installed {
err = fmt.Errorf("There is no module named ", modname, " installed.")
}
var viewname string
if len(uni.Paths) < 4 {
viewname = "index"
} else {
viewname = uni.Paths[3]
}
uni.Caller.Call("views", modname, "AdminInit", nil)
sanitized_viewname := Viewnameize(viewname)
if !uni.Caller.Has("views", modname, sanitized_viewname) {
err = fmt.Errorf("Module %v has no view named %v.", modname, sanitized_viewname)
}
ret_rec := func(e error) {
err = e
}
uni.Dat["_points"] = []string{modname + "/" + viewname}
uni.Caller.Call("views", modname, sanitized_viewname, ret_rec)
}
return err
}
示例3: Index
func (v *V) Index() error {
uni := v.uni
var search string
if s, hass := uni.Req.Form["point-name"]; hass {
search = s[0]
}
points, ok := jsonp.Get(uni.Opt, "Display-points")
if !ok {
// return fmt.Errorf("There is no \"Display-points\" field in the option document.") // Rather than freezing we easily recover here below.
points = map[string]interface{}{}
}
// TODO: clean up here and make it more straightforward.
points_m := points.(map[string]interface{})
has_points := false
ps := []string{}
if ok {
for key, _ := range points_m {
if search == "" || strings.Index(key, search) != -1 {
ps = append(ps, key)
}
has_points = true
}
}
uni.Dat["has_points"] = has_points
sort.Strings(ps)
uni.Dat["point_names"] = ps
uni.Dat["search"] = search
uni.Dat["_points"] = []string{"display_editor/index"}
return nil
}
示例4: allowsComment
// Return values: content type, general (fatal) error, puzzle error
// Puzzle error is returned to support the decision of wether to put the comment into a moderation queue.
func (a *A) allowsComment(op string) (string, error, error) {
uni := a.uni
inp := uni.Req.Form
user_level := scut.Ulev(uni.Dat["_user"])
content_id := bson.ObjectIdHex(inp["content_id"][0])
typ, err := content_model.TypeOf(uni.Db, content_id)
if err != nil {
return "", err, nil
}
auth_opts, ignore := user.AuthOpts(uni, "content.types."+typ, op+"_comment")
if ignore {
return "", fmt.Errorf("Auth options should not be ignored."), nil
}
err, puzzle_err := user.AuthAction(uni, auth_opts)
if err != nil {
return "", err, nil
}
var user_id bson.ObjectId
user_id_i, has := jsonp.Get(uni.Dat, "_user._id") // At this point the user will have a user id. TODO: except when the auth_opts is misconfigured.
if !has {
return "", fmt.Errorf("User has no id."), nil
}
if has {
user_id = user_id_i.(bson.ObjectId)
}
if op != "insert" {
err = content_model.CanModifyComment(uni.Db, inp, 300, user_id, user_level) // TODO: remove hard-coded value.
}
return typ, err, puzzle_err
}
示例5: update
// Update content.
// TODO: Consider separating the shared processes of Insert/Update (type and rule checking, extracting)
func (a *A) update() error {
uni := a.uni
uid, typ, prep_err := a.allowsContent("insert")
if prep_err != nil {
return prep_err
}
rule, hasrule := jsonp.Get(uni.Opt, "Modules.content.types."+typ+".rules")
if !hasrule {
return fmt.Errorf("Can't find content type rules " + typ)
}
err := content_model.Update(uni.Db, uni.Ev, rule.(map[string]interface{}), uni.Req.Form, uid)
if err != nil {
return err
}
draft_id, has_draft_id := uni.Req.Form[content_model.Parent_draft_field]
content_id := uni.Req.Form["id"][0]
if has_draft_id && len(draft_id[0]) > 0 { // Coming from draft.
// We must set redirect because it can come from draft edit too.
uni.Dat["_cont"] = map[string]interface{}{
"!type": typ,
"!id": content_id,
}
} else {
uni.Dat["_cont"] = map[string]interface{}{
"!type": typ,
}
}
return nil
}
示例6: Load
// Searches all {{load modname/filename.ext}} and replaces that with the proper requires then calls the require module on the file.
func Load(opt_i interface{}, root string, file []byte, get func(string, string) ([]byte, error)) ([]byte, error) {
r := regexp.MustCompile(beg + "([a-zA-Z_.:/-])*" + end)
s := r.FindAllString(string(file), -1)
cut_beg := len(beg)
cut_end := len(end)
for _, v := range s {
replacement := []byte{}
load_name := v[cut_beg : len(v)-cut_end]
loads, has := jsonp.Get(opt_i, load_name)
if has {
req_paths := jsonp.ToStringSlice(loads.([]interface{}))
for _, x := range req_paths {
replacement = append(replacement, []byte(fmt.Sprintf("{{require %v}}", x))...)
}
}
if len(replacement) > 0 {
str, err := require.RMem(root, replacement, get)
if err != nil {
return nil, err
}
replacement = []byte(str)
}
file = r.ReplaceAll(file, replacement)
}
return file, nil
}
示例7: eval_rec
func eval_rec(i interface{}, vars map[string]interface{}, nested bool) interface{} {
switch val := i.(type) {
case string:
if string(val[0]) == Marker {
if string(val[1]) == "&" { // Reference
if nested {
panic("Can't interpret reference in map or slice.")
} else {
return Ref{vars, string(val[2:])}
}
} else { // Variable
val, _ := jsonp.Get(vars, val[1:])
return val
}
} else {
return i
}
case map[string]interface{}:
for i, v := range val {
val[i] = eval_rec(v, vars, true)
}
case []interface{}:
for i, v := range val {
val[i] = eval_rec(v, vars, true)
}
default:
return i
}
return i
}
示例8: contentView
func (h *H) contentView(content_map map[string]string) (error, bool) {
uni := h.uni
types, ok := jsonp.Get(uni.Opt, "Modules.content.types")
if !ok {
return fmt.Errorf("No content types."), false
}
slug_keymap := map[string]struct{}{}
for _, v := range types.(map[string]interface{}) {
type_conf := v.(map[string]interface{})
if slugval, has := type_conf["accessed_by"]; has {
slug_keymap[slugval.(string)] = struct{}{}
} else {
slug_keymap["slug"] = struct{}{}
}
}
slug_keys := []string{}
for i, _ := range slug_keymap {
slug_keys = append(slug_keys, i)
}
content, found := content_model.FindContent(uni.Db, slug_keys, content_map["slug"])
if !found {
return nil, false
}
dont_query := map[string]interface{}{"password": 0}
resolver.ResolveOne(uni.Db, content, dont_query)
uni.Dat["_points"] = []string{"content"}
uni.Dat["content"] = content
return nil, true
}
示例9: DereferStrict
func (r Ref) DereferStrict() interface{} {
val, ok := jsonp.Get(r.vars, r.name)
if !ok {
panic(r.name + " is undefined.")
}
return val
}
示例10: allowsContent
func (a *A) allowsContent(op string) (bson.ObjectId, string, error) {
uni := a.uni
var typ string
if op == "insert" {
typ = uni.Req.Form["type"][0] // See TODO below.
} else {
content_id := patterns.ToIdWithCare(uni.Req.Form["id"][0]) // TODO: Don't let it panic if id does not exists, return descriptive error message.
_typ, err := content_model.TypeOf(uni.Db, content_id)
if err != nil {
return "", "", err
}
typ = _typ
}
auth_opts, ignore := user.AuthOpts(uni, "content.types."+typ, op)
if ignore {
return "", "", fmt.Errorf("Auth options should not be ignored.")
}
err, _ := user.AuthAction(uni, auth_opts)
if err != nil {
return "", "", err
}
uid_i, has_uid := jsonp.Get(uni.Dat, "_user._id")
if !has_uid {
return "", "", fmt.Errorf("Can't %v content, you have no id.", op)
}
uid := uid_i.(bson.ObjectId)
user_level := scut.Ulev(uni.Dat["_user"])
allowed_err := content_model.CanModifyContent(uni.Db, uni.Req.Form, 300, uid, user_level)
if allowed_err != nil {
return "", "", allowed_err
}
return uid, typ, nil
}
示例11: musth
func musth(a string, b map[string]interface{}) error {
_, has := jsonp.Get(b, a)
if !has {
return fmt.Errorf("Map has no key \"%v\". Terminating.", a)
}
return nil
}
示例12: D
// Displays a display point.
func D(uni *context.Uni) {
points, points_exist := uni.Dat["_points"]
var point string
if points_exist {
point = points.([]string)[0]
} else {
p := uni.Req.URL.Path
if p == "/" {
point = "index"
} else {
point = p
}
}
queries, queries_exists := jsonp.Get(uni.Opt, "Display-points."+point+".queries")
if queries_exists {
qmap, ok := queries.(map[string]interface{})
if ok {
runQueries(uni, qmap)
}
}
BeforeDisplay(uni)
// While it is not the cheapest solution to convert bson.ObjectIds to strings here, where we have to iterate trough all values,
// it is still better than remembering (and forgetting) to convert it at every specific place.
scut.IdsToStrings(uni.Dat)
langs, _ := jsonp.Get(uni.Dat, "_user.languages") // _user always has language member
langs_s := toStringSlice(langs)
loc, _ := display_model.LoadLocStrings(uni.Dat, langs_s, uni.Root, scut.GetTPath(uni.Opt, uni.Req.Host), nil) // TODO: think about errors here.
if loc != nil {
uni.Dat["loc"] = loc
}
if _, isjson := uni.Req.Form["json"]; isjson {
putJSON(uni)
return
} else {
err := DisplayFile(uni, point)
if err != nil {
uni.Dat["missing_file"] = point
err_404 := DisplayFile(uni, "404")
if err_404 != nil {
uni.Put("Cant find file: ", point)
}
}
}
}
示例13: OkayToDoAction
// A very basic framework to provide an easy way to do action based authorization (currently checks user levels and puzzles).
// Hopefully this will solve the common security problem of forgetting to check the user's rights in modules,
// since everything is blacklisted by default (needs admin rights).
//
// Example:
// "Modules.%v.actions.%v.auth" : {
// "min_lev": 0, // Defaults to 300. 0 Means somebody who has a user level >= min_lev can do it.
// "no_puzzles_lev": 2 // Defaults to 2. Means someone who has a user level >= no_puzzles_lev will not have to solve the spam protection puzzle.
// "puzzles": ["timer"] // Defaults to defaultPuzzles(uni).
// "hot_reg": 2 // More precisely: "reg, login, build".
// // Defaults to 0. Specifies wether to register, login and build a guest user.
// // 0 means don't register at all. 1 means register if he solved the puzzles. 2 register even if he failed the puzzles (useful for moderation).
// }
//
// A value of false means proceed as passed. This is useful when the rights to an action can not be determined by only
// from the module and action name. A good example is the content module. An action of "insert", or "comment_insert" can belong
// to different types of content, thus requiring different levels.
// We can solve this problem by assigning "Modules.content.actions.insert.auth" = false
// and calling this function by hand as mod_name = "content.types.blog", action_name = "insert" => "Modules.content.types.blog.actions.insert.auth" (long, I know...).
//
// Better workaround must exists, but currently we go on with this in the content module.
// First error is general error, not meant to be ignored, second is puzzle error, which can be ignored if one wants implement moderation.
func OkayToDoAction(uni *context.Uni, mod_name, action_name string) (error, error) {
if _, installed := jsonp.Get(uni.Opt, "Modules."+mod_name); !installed {
return fmt.Errorf(cant_run_back, action_name, mod_name), nil
}
auth_options, explicit_ignore := AuthOpts(uni, mod_name, action_name)
if explicit_ignore {
return nil, nil
}
return AuthAction(uni, auth_options)
}
示例14: SavePersonalTypeConfig
// TODO: Ugly name.
func (a *A) SavePersonalTypeConfig() error {
uni := a.uni
return fmt.Errorf(not_impl) // Temp.
user_id_i, has := jsonp.Get(uni.Dat, "_user._id")
if !has {
return fmt.Errorf("Can't find user id.")
}
user_id := user_id_i.(bson.ObjectId)
return content_model.SavePersonalTypeConfig(uni.Db, uni.Req.Form, user_id)
}
示例15: InstallB
// opt structure:
// Modules.modulename
func InstallB(db *mgo.Database, ev ifaces.Event, opt map[string]interface{}, modn, mode string) (bson.ObjectId, error) {
var object_id bson.ObjectId
if _, already := jsonp.Get(opt, "Modules."+modn); mode == "install" && already {
return object_id, fmt.Errorf("Module " + modn + " is already installed.")
} else if mode == "uninstall" && !already {
return object_id, fmt.Errorf("Module " + modn + " is not installed.")
}
object_id = basic.CreateOptCopy(db)
return object_id, nil
}