master
Raw Download raw file
 1package main
 2
 3import (
 4	"net/http"
 5
 6	"github.com/russross/blackfriday"
 7)
 8
 9func main() {
10	mux := http.NewServeMux()
11	http.Handle("/markdown", GenerateMarkdown())
12	http.Handle("/", http.FileServer(http.Dir("public")))
13	http.ListenAndServe(":8080", nil)
14}
15
16func GenerateMarkdown() http.Handler {
17	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18		switch r.Method {
19		case "POST":
20			markdown := blackfriday.MarkdownCommon([]byte(r.FormValue("body")))
21			w.Write(markdown)
22			return
23		case "GET":
24			http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
25		}
26
27	})
28}