本文整理汇总了Golang中github.com/opesun/hypecms/api/context.Uni.Put方法的典型用法代码示例。如果您正苦于以下问题:Golang Uni.Put方法的具体用法?Golang Uni.Put怎么用?Golang Uni.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/opesun/hypecms/api/context.Uni
的用法示例。
在下文中一共展示了Uni.Put方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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()
}
}