• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang jsonp.Get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/opesun/jsonp.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:Laller,项目名称:hypecms,代码行数:15,代码来源:content-v.go


示例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
}
开发者ID:Laller,项目名称:hypecms,代码行数:49,代码来源:admin-v.go


示例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
}
开发者ID:Laller,项目名称:hypecms,代码行数:30,代码来源:display-editor.go


示例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
}
开发者ID:Laller,项目名称:hypecms,代码行数:32,代码来源:content-m.go


示例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
}
开发者ID:Laller,项目名称:hypecms,代码行数:31,代码来源:content-m.go


示例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
}
开发者ID:Laller,项目名称:chill,代码行数:27,代码来源:load.go


示例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
}
开发者ID:crufter,项目名称:jsonlang,代码行数:30,代码来源:jsonlang.go


示例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
}
开发者ID:Laller,项目名称:hypecms,代码行数:29,代码来源:content-v.go


示例9: DereferStrict

func (r Ref) DereferStrict() interface{} {
	val, ok := jsonp.Get(r.vars, r.name)
	if !ok {
		panic(r.name + " is undefined.")
	}
	return val
}
开发者ID:crufter,项目名称:jsonlang,代码行数:7,代码来源:jsonlang.go


示例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
}
开发者ID:Laller,项目名称:hypecms,代码行数:33,代码来源:content-m.go


示例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
}
开发者ID:Laller,项目名称:hypecms,代码行数:7,代码来源:shell.go


示例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)
			}
		}
	}
}
开发者ID:Laller,项目名称:hypecms,代码行数:45,代码来源:display.go


示例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)
}
开发者ID:Laller,项目名称:hypecms,代码行数:32,代码来源:action-auth.go


示例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)
}
开发者ID:Laller,项目名称:hypecms,代码行数:11,代码来源:content-m.go


示例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
}
开发者ID:Laller,项目名称:hypecms,代码行数:12,代码来源:admin-model.go


示例16: Config

func (v *V) Config() error {
	uni := v.uni
	op, _ := jsonp.Get(uni.Opt, "Modules.content")
	marsh, err := json.MarshalIndent(op, "", "    ")
	if err != nil {
		return fmt.Errorf("Can't marshal content options.")
	}
	uni.Dat["content_options"] = string(marsh)
	return nil
}
开发者ID:Laller,项目名称:hypecms,代码行数:10,代码来源:content-v.go


示例17: ownLev

func (h *HighLev) ownLev() (int, bool) {
	verbL, ok := jsonp.Get(h.nouns, fmt.Sprintf("%v.verbs.%v.ownLevel", h.desc.Sentence.Noun, h.desc.Sentence.Verb))
	if ok {
		return numcon.IntP(verbL), true
	}
	nounL, ok := jsonp.GetM(h.nouns, fmt.Sprintf("%v.ownLevel", h.desc.Sentence.Noun))
	if ok {
		return numcon.IntP(nounL), true
	}
	return 0, false
}
开发者ID:crufter,项目名称:nocrud,代码行数:11,代码来源:highlev.go


示例18: getSidebar

func (v *V) getSidebar() []string {
	uni := v.uni
	menu := []string{}
	types, has := jsonp.Get(uni.Opt, "Modules.content.types")
	if !has {
		panic("There are no content types.")
	}
	for i, _ := range types.(map[string]interface{}) {
		menu = append(menu, i)
	}
	return menu
}
开发者ID:Laller,项目名称:hypecms,代码行数:12,代码来源:content-v.go


示例19: DeleteComment

func (a *A) DeleteComment() error {
	uni := a.uni
	_, allow_err, _ := a.allowsComment("delete")
	if allow_err != nil {
		return allow_err
	}
	uid, has_uid := jsonp.Get(uni.Dat, "_user._id")
	if !has_uid {
		return fmt.Errorf("Can't delete comment, you have no id.")
	}
	return content_model.DeleteComment(uni.Db, uni.Ev, uni.Req.Form, uid.(bson.ObjectId))
}
开发者ID:Laller,项目名称:hypecms,代码行数:12,代码来源:content-m.go


示例20: Set

func (r Ref) Set(a interface{}) {
	// TODO: this will not handle []s, set should be implemented in opesun/jsonp.
	sl := strings.Split(r.name, ".")
	l := len(sl)
	if l == 1 {
		r.vars[r.name] = a
	} else {
		// TODO: This is not generic yet!
		val, _ := jsonp.Get(r.vars, strings.Join(sl[:l-1], "."))
		name := sl[l-1:][0]
		val.(map[string]interface{})[name] = val
	}
}
开发者ID:crufter,项目名称:jsonlang,代码行数:13,代码来源:jsonlang.go



注:本文中的github.com/opesun/jsonp.Get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang util.ObjectLoad函数代码示例发布时间:2022-05-29
下一篇:
Golang log.Warnf函数代码示例发布时间:2022-05-29
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap