示例#1
0
文件: content.go 项目: ninnemana/API
func GetContent(rw http.ResponseWriter, req *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string {
	var c site.Content
	var err error
	idStr := params["id"]
	id, err := strconv.Atoi(idStr)

	if err == nil {
		//Thar be an Id int
		c.Id = id
		err = c.Get(dtx)
		if err != nil {
			apierror.GenerateError("Trouble getting site content by Id.", err, rw, req)
			return ""
		}
	}

	//Thar be a slug
	c.Slug = idStr
	err = c.GetBySlug(dtx)
	if err != nil {
		apierror.GenerateError("Trouble getting site content by slug.", err, rw, req)
		return ""
	}

	return encoding.Must(enc.Encode(c))
}