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