本文整理汇总了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)
}
示例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()
}
}
示例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()
}
}
示例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))
}
示例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
}
示例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)
}
}
}
}
示例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)
}
}
示例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
}
示例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
}
示例10: showTimer
func showTimer(uni *context.Uni, puzzle_opt map[string]interface{}) (string, error) {
return user_model.ShowTimer(uni.Secret(), puzzle_opt)
}
示例11: solveTimer
func solveTimer(uni *context.Uni, puzzle_opts map[string]interface{}) error {
return user_model.SolveTimer(uni.Secret(), uni.Req.Form, puzzle_opts)
}
示例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()
}
}