Esempio n. 1
0
// get page meta
func HandlePageMeta(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	id := ps.ByName("id")
	page, err := GetPage(id)
	if err != nil {
		webutils.WriteErrorResponse(w, err)
		return
	}
	var pageMeta PageMeta
	host, err := getHost(page.URL)
	if err != nil {
		webutils.WriteErrorResponse(w, err)
		return
	}
	pageMeta = PageMeta{page.ID, page.Title, page.URL, host, page.CreatedAt}
	webutils.WriteResponse(w, pageMeta)
}
Esempio n. 2
0
func HandleAddPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	decoder := json.NewDecoder(r.Body)
	var page Page
	err := decoder.Decode(&page)
	if err != nil {
		webutils.WriteErrorResponse(w, err)
		return
	}
	page.ID = bson.NewObjectId()
	page.CreatedAt = time.Now()
	err = StorePage(&page)
	if err != nil {
		webutils.WriteErrorResponse(w, err)
		return
	}
	webutils.WriteResponse(w, page.ID.Hex())
}
Esempio n. 3
0
// delete a page
func HandleDeletePage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	id := ps.ByName("id")
	err := DeletePage(id)
	if err != nil {
		webutils.WriteErrorResponse(w, err)
		return
	}
	webutils.WriteResponse(w, id)
}