예제 #1
0
func (this DocsController) GetDocAsHtml(rw http.ResponseWriter, req *http.Request, params mux.Params) {
	var fp string
	var err error

	DocName := fp_utils.TrimExt(params.ByName("name"))
	fp = getDocTextFilePath(this.DocRoot, DocName)

	if fs_utils.Exists(fp) != true {
		rw.WriteHeader(http.StatusNoContent)
		return
	}

	html, err := readPageAsHtml(DocName, fp)
	if err != nil {
		// TODO:MED instead of returning status 500 here,
		// perhaps should return status OK (200) with
		// an error message.
		rw.WriteHeader(500)
		log.Errorf("ERROR %s", err.Error())
		return
	}

	_, err = rw.Write(html)
	if err != nil {
		http.NotFound(rw, req)
		log.Errorf("ERROR %s", err.Error())
		return
	}
}
예제 #2
0
func (this DocsController) GetDocAsMarkDown(rw http.ResponseWriter, req *http.Request, params mux.Params) {
	var fp string

	DocName := fp_utils.TrimExt(params.ByName("name"))
	fp = getDocTextFilePath(this.DocRoot, DocName)

	//log.Infof(fp)

	data, err := ioutil.ReadFile(fp)
	if err != nil {
		// TODO:MED I'm just assuming the page file isn't here.
		// It might be better to detect the error type here
		// if possible.
		rw.WriteHeader(http.StatusNoContent)
		return
	}

	// WARNING: We don't escape any of the user input data here.
	// I guess this should be OK if the raw data isn't displayed
	// as HTML anywhere.
	unsafe := data

	_, err = rw.Write(unsafe)
	if err != nil {
		log.Errorf("ERROR %s", err.Error())
		return
	}
}
예제 #3
0
func (this DocsController) GetDocSummary(rw http.ResponseWriter, req *http.Request, params mux.Params) {
	// TODO:HIGH this removing the extension here shouldn't be required
	// but we'll leave it for now.
	DocName := fp_utils.TrimExt(params.ByName("name"))
	fp := getDocPreviewFilePath(this.DocRoot, DocName)

	if fs_utils.Exists(fp) != true {
		rw.WriteHeader(http.StatusNoContent)
		return
	}

	data, err := readPageSummary(fp)
	if err != nil {
		// TODO:MED instead of returning status 500 here,
		// perhaps should return status OK (200) with
		// an error message.
		rw.WriteHeader(500)
		log.Errorf("ERROR %s", err.Error())
		return
	}

	// WARNING: We don't escape any of the user input data here.
	// I guess this should be OK if the raw data isn't displayed
	// as HTML anywhere.
	unsafe := data

	_, err = rw.Write(unsafe)
	if err != nil {
		log.Errorf("ERROR %s", err.Error())
		return
	}

}