Go lang template http.FileSystem
$ go get github.com/dolfly/httpfs/templatefs
import "github.com/dolfly/httpfs/templatefs"
package main
import (
"github.com/dolfly/httpfs/templatefs"
"github.com/dolfly/httpfs/templatefs/engines/markdown"
"net/http"
)
func main() {
fs := templatefs.New(http.Dir("templates"), nil, &markdown.Engine{})
http.Handle("/", http.FileServer(fs))
http.ListenAndServe(":8080", nil)
}
Simple markdown webserver
package main
import (
"github.com/dolfly/httpfs/templatefs"
"github.com/dolfly/httpfs/templatefs/engines/markdown"
"net/http"
"strings"
"unicode"
)
func main() {
s := `
<!DOCTYPE html>
<html>
<head>
<title>{{ .Title }}</title>
<meta charset="utf-8">
{{- if .CSS}}
<link rel="stylesheet" type="text/css" href="{{ .CSS }}">
{{- end}}
</head>
<body>
{{ .Body | safehtml }}
</body>
</html>
`
layout, err := templatefs.NewLayout(strings.TrimLeftFunc(s, unicode.IsSpace))
if err != nil {
return
}
fs := templatefs.New(http.Dir("templates"), layout, &markdown.Engine{})
http.Handle("/", http.FileServer(fs))
http.ListenAndServe(":8080", nil)
}
Simple markdown webserver with custom layout