From 04c41b6f74b4762555a56b056db4ab5e123a609a Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 24 Feb 2024 14:17:33 +0100 Subject: html/template --- .dockerignore | 1 - Dockerfile | 3 +-- Makefile | 13 ------------- cert/.gitkeep | 0 go.mod | 5 +++++ go.sum | 2 ++ handler.go | 13 +------------ main.go | 24 ++++++++++++++++++++++++ wiki.go | 21 +++------------------ 9 files changed, 36 insertions(+), 46 deletions(-) delete mode 100644 Makefile delete mode 100644 cert/.gitkeep create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.dockerignore b/.dockerignore index 8695629..ebba552 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ .git data/* -cert/* *.swp diff --git a/Dockerfile b/Dockerfile index 06be74b..cfa0e2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ FROM golang:onbuild ENV LANG=C.UTF-8 VOLUME /go/src/app/data -VOLUME /go/src/app/cert -EXPOSE 8080 8443 +EXPOSE 8080 diff --git a/Makefile b/Makefile deleted file mode 100644 index 6e0d3ba..0000000 --- a/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -TAG = dim13/gowiki - -build: clean - docker build -t ${TAG} --rm --no-cache . - -push: build - docker push ${TAG} - -clean: - go clean - -rmi: - docker images -f 'dangling=true' -q | xargs docker rmi diff --git a/cert/.gitkeep b/cert/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f211e3f --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module dim13.org/gowiki + +go 1.22.0 + +require github.com/russross/blackfriday v1.6.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..270cecf --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= +github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= diff --git a/handler.go b/handler.go index 369da40..8894b62 100644 --- a/handler.go +++ b/handler.go @@ -1,22 +1,11 @@ package main import ( + "html/template" "io/ioutil" "net/http" - "text/template" ) -func init() { - http.Handle("/css/", http.FileServer(http.Dir("assets"))) - http.Handle("/fonts/", http.FileServer(http.Dir("assets"))) - http.HandleFunc("/index", indexHandler) - http.HandleFunc("/view/", viewHandler) - http.HandleFunc("/edit/", editHandler) - http.HandleFunc("/del/", delHandler) - http.HandleFunc("/save/", saveHandler) - http.HandleFunc("/", homeHandler) -} - var ( indextmpl = template.Must(template.ParseFiles("tmpl/root", "tmpl/index")) viewtmpl = template.Must(template.ParseFiles("tmpl/root", "tmpl/view")) diff --git a/main.go b/main.go new file mode 100644 index 0000000..2c50720 --- /dev/null +++ b/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "flag" + "net/http" +) + +var ( + listen = flag.String("listen", ":8080", "Listen at") + data = flag.String("data", "data", "Data dir") +) + +func main() { + flag.Parse() + http.Handle("/css/", http.FileServer(http.Dir("assets"))) + http.Handle("/fonts/", http.FileServer(http.Dir("assets"))) + http.HandleFunc("/index", indexHandler) + http.HandleFunc("/view/", viewHandler) + http.HandleFunc("/edit/", editHandler) + http.HandleFunc("/del/", delHandler) + http.HandleFunc("/save/", saveHandler) + http.HandleFunc("/", homeHandler) + http.ListenAndServe(*listen, nil) +} diff --git a/wiki.go b/wiki.go index 8afd5fd..6a7bbf9 100644 --- a/wiki.go +++ b/wiki.go @@ -1,24 +1,15 @@ package main import ( - "flag" + "html/template" "io/ioutil" "net/http" "os" "path" - "text/template" "github.com/russross/blackfriday" ) -var ( - listen = flag.String("listen", ":8080", "Listen at") - listentls = flag.String("listentls", ":8443", "Listen TLS at") - cert = flag.String("cert", "cert/cert.pem", "TLS Certificate") - key = flag.String("key", "cert/key.pem", "TLS Key") - data = flag.String("data", "data", "Data dir") -) - type Page struct { Title string Body []byte @@ -50,12 +41,6 @@ func (p *Page) render(w http.ResponseWriter, tmpl *template.Template) { } } -func (p *Page) HTML() string { - return string(blackfriday.MarkdownCommon([]byte(p.Body))) -} - -func main() { - flag.Parse() - go http.ListenAndServeTLS(*listentls, *cert, *key, nil) - http.ListenAndServe(*listen, nil) +func (p *Page) HTML() template.HTML { + return template.HTML(blackfriday.MarkdownCommon(p.Body)) } -- cgit v1.2.3