示例#1
0
文件: handlers.go 项目: tcard/goci
func handle_recent_json(w http.ResponseWriter, req *http.Request, ctx *Context) {
	ws, err := worker.GetRecentWork(ctx.Context, recent_amount)
	if err != nil {
		internal_error(w, req, ctx, err)
		return
	}
	if err := send_json(w, ws); err != nil {
		log.Println("error responding with json:", err)
	}
}
示例#2
0
文件: handlers.go 项目: tcard/goci
func handle_recent_html(w http.ResponseWriter, req *http.Request, ctx *Context) {
	ws, err := worker.GetRecentWork(ctx.Context, recent_amount)
	if err != nil {
		internal_error(w, req, ctx, err)
		return
	}
	w.Header().Set("Content-Type", "text/html")
	err = recent_template.Execute(w, ws)
	if err != nil {
		internal_error(w, req, ctx, err)
	}
}
示例#3
0
文件: handlers.go 项目: tcard/goci
//our basic handle index that demonstrates how to get data from the context
//inside a template
func handle_index(w http.ResponseWriter, req *http.Request, ctx *Context) {
	if req.URL.Path != "/" {
		perform_status(w, ctx, http.StatusNotFound)
		return
	}
	w.Header().Set("Content-type", "text/html")
	ws, err := worker.GetRecentWork(ctx.Context, recent_amount)
	if err != nil {
		internal_error(w, req, ctx, err)
		return
	}
	ctx.Set("Recent", ws)
	ctx.Meta.JS.Append("recent.js")
	base_execute(w, ctx, tmpl_root("blocks", "index.block"), tmpl_root("blocks", "recent.block"))
}