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

Golang context.Uni类代码示例

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

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



在下文中一共展示了Uni类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: DErr

// This is called if an error occured in a front hook.
func DErr(uni *context.Uni, err error) {
	if _, isjson := uni.Req.Form["json"]; isjson {
		putJSON(uni)
		return
	}
	uni.Put(err)
}
开发者ID:Laller,项目名称:hypecms,代码行数:8,代码来源:display.go


示例2: queryErr

// Prints errors during query running to http response. (Kinda nonsense now as it is.)
func queryErr(uni *context.Uni) {
	r := recover()
	if r != nil {
		uni.Put("There was an error running the queries: ", r)
		debug.PrintStack()
	}
}
开发者ID:Laller,项目名称:hypecms,代码行数:8,代码来源:display.go


示例3: displErr

// Prints errors during template file display to http response. (Kinda nonsense now as it is.)
func displErr(uni *context.Uni) {
	r := recover()
	if r != nil {
		uni.Put("There was an error executing the template.")
		fmt.Println("problem with template: ", r)
		debug.PrintStack()
	}
}
开发者ID:Laller,项目名称:hypecms,代码行数:9,代码来源:display.go


示例4: putJSON

// Prints all available data to http response as a JSON.
func putJSON(uni *context.Uni) {
	var v []byte
	if _, format := uni.Req.Form["fmt"]; format {
		v, _ = json.MarshalIndent(uni.Dat, "", "    ")
	} else {
		v, _ = json.Marshal(uni.Dat)
	}
	uni.W.Header().Set("Content-Type", "application/json; charset=utf-8")
	uni.Put(string(v))
}
开发者ID:Laller,项目名称:hypecms,代码行数:11,代码来源:display.go


示例5: DisplayTemplate

// Tries to dislay a template file.
func DisplayTemplate(uni *context.Uni, filep string) error {
	_, src := uni.Req.Form["src"]
	file, err := require.R("", filep+".tpl",
		func(root, fi string) ([]byte, error) {
			return GetFileAndConvert(uni.Root, fi, uni.Opt, uni.Req.Host, nil)
		})
	if err != nil {
		return fmt.Errorf("Cant find template file %v.", filep)
	}
	if src {
		uni.Put(string(file))
		return nil
	}
	uni.Dat["_tpl"] = "/templates/" + scut.TemplateType(uni.Opt) + "/" + scut.TemplateName(uni.Opt) + "/"
	prepareAndExec(uni, string(file))
	return nil
}
开发者ID:Laller,项目名称:hypecms,代码行数:18,代码来源:display.go


示例6: 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


示例7: actionResponse

// After running a background operation this either redirects with data in url paramters or prints out the json encoded result.
func actionResponse(uni *context.Uni, err error, action_name string) {
	if DEBUG {
		fmt.Println(uni.Req.Referer())
		fmt.Println("	", err)
	}
	_, is_json := uni.Req.Form["json"]
	redir := uni.Req.Referer()
	if red, ok := uni.Dat["redirect"]; ok {
		redir = red.(string)
	} else if post_red, okr := uni.Req.Form["redirect"]; okr && len(post_red) == 1 {
		redir = post_red[1]
	}
	var cont map[string]interface{}
	cont_i, has := uni.Dat["_cont"]
	if has {
		cont = cont_i.(map[string]interface{})
	} else {
		cont = map[string]interface{}{}
	}
	redir = appendParams(redir, action_name, err, cont)
	if is_json {
		cont["redirect"] = redir
		if err == nil {
			cont["ok"] = true
		} else {
			cont["error"] = err.Error()
		}
		var v []byte
		if _, fmt := uni.Req.Form["fmt"]; fmt {
			v, _ = json.MarshalIndent(cont, "", "    ")
		} else {
			v, _ = json.Marshal(cont)
		}
		uni.Put(string(v))
	} else {
		http.Redirect(uni.W, uni.Req, redir, 303)
	}
}
开发者ID:Laller,项目名称:hypecms,代码行数:39,代码来源:main.go


示例8: DisplayFallback

// Tries to display a module file.
func DisplayFallback(uni *context.Uni, filep string) error {
	_, src := uni.Req.Form["src"]
	if strings.Index(filep, "/") != -1 {
		return fmt.Errorf("Nothing to fall back to.") // No slash in fallback path means no modulename to fall back to.
	}
	if scut.PossibleModPath(filep) {
		return fmt.Errorf("Not a possible fallback path.")
	}
	file, err := require.R("", filep+".tpl", // Tricky, care.
		func(root, fi string) ([]byte, error) {
			return GetFileAndConvert(uni.Root, fi, uni.Opt, uni.Req.Host, nil)
		})
	if err != nil {
		fmt.Errorf("Cant find fallback file %v.", filep)
	}
	if src {
		uni.Put(string(file))
		return nil
	}
	uni.Dat["_tpl"] = "/modules/" + strings.Split(filep, "/")[0] + "/tpl/"
	prepareAndExec(uni, string(file))
	return nil
}
开发者ID:Laller,项目名称:hypecms,代码行数:24,代码来源:display.go


示例9: RegLoginBuild

// Helper function to hotregister a guest user, log him in and build his user data into uni.Dat["_user"].
func RegLoginBuild(uni *context.Uni, solved_puzzle bool) error {
	db := uni.Db
	ev := uni.Ev
	guest_rules := guestRules(uni)
	inp := uni.Req.Form
	http_header := uni.Req.Header
	dat := uni.Dat
	w := uni.W
	block_key := []byte(uni.Secret())
	guest_id, err := user_model.RegisterGuest(db, ev, guest_rules, inp, solved_puzzle)
	if err != nil {
		return err
	}
	err = user_model.Login(w, guest_id, block_key)
	if err != nil {
		return err
	}
	user, err := user_model.BuildUser(db, ev, guest_id, http_header)
	if err != nil {
		return err
	}
	dat["_user"] = user
	return nil
}
开发者ID:Laller,项目名称:hypecms,代码行数:25,代码来源:action-auth.go


示例10: showTimer

func showTimer(uni *context.Uni, puzzle_opt map[string]interface{}) (string, error) {
	return user_model.ShowTimer(uni.Secret(), puzzle_opt)
}
开发者ID:Laller,项目名称:hypecms,代码行数:3,代码来源:action-auth.go


示例11: solveTimer

func solveTimer(uni *context.Uni, puzzle_opts map[string]interface{}) error {
	return user_model.SolveTimer(uni.Secret(), uni.Req.Form, puzzle_opts)
}
开发者ID:Laller,项目名称:hypecms,代码行数:3,代码来源:action-auth.go


示例12: adErr

func adErr(uni *context.Uni) {
	if r := recover(); r != nil {
		uni.Put("There was an error running the admin module.\n", r)
		debug.PrintStack()
	}
}
开发者ID:Laller,项目名称:hypecms,代码行数:6,代码来源:admin-m.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang jsonp.Get函数代码示例发布时间:2022-05-28
下一篇:
Golang goquery.ParseUrl函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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