diff --git a/Makefile b/Makefile index 49dc584..dd9d604 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ run: build ./mycorrhiza metarrhiza build: + go generate go build . test: diff --git a/go.mod b/go.mod index 84004ef..17f2ff6 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/bouncepaw/mycorrhiza go 1.14 + +require github.com/valyala/quicktemplate v1.6.2 diff --git a/go.sum b/go.sum index e69de29..344ceb3 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,15 @@ +github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= +github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.15.1/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= +github.com/valyala/quicktemplate v1.6.2 h1:k0vgK7zlmFzqAoIBIOrhrfmZ6JoTGJlLRPLbkPGr2/M= +github.com/valyala/quicktemplate v1.6.2/go.mod h1:mtEJpQtUiBV0SHhMX6RtiJtqxncgrfmjcUy5T68X8TM= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/history/information.go b/history/information.go index eff1e78..ff6e654 100644 --- a/history/information.go +++ b/history/information.go @@ -48,8 +48,7 @@ func (rev *Revision) AsHtmlTableRow(hyphaName string) string { %s %s - %s -`, rev.Time.Format(time.RFC822), rev.Hash, hyphaName, rev.Hash, rev.Username, rev.Message) +`, rev.Time.Format(time.RFC822), rev.Hash, hyphaName, rev.Hash, rev.Message) } // See how the file with `filepath` looked at commit with `hash`. diff --git a/http_mutators.go b/http_mutators.go index 2db520a..e3cd397 100644 --- a/http_mutators.go +++ b/http_mutators.go @@ -9,6 +9,8 @@ import ( "path/filepath" "github.com/bouncepaw/mycorrhiza/history" + "github.com/bouncepaw/mycorrhiza/templates" + "github.com/bouncepaw/mycorrhiza/util" ) func init() { @@ -38,24 +40,7 @@ func handlerEdit(w http.ResponseWriter, rq *http.Request) { } else { warning = `

You are creating a new hypha.

` } - form := fmt.Sprintf(` -
-

Edit %[1]s

- %[3]s -
- -
- - Cancel -
-
-`, hyphaName, textAreaFill, warning) - - w.Header().Set("Content-Type", "text/html;charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write([]byte(base( - "Edit "+hyphaName, form))) + util.HTTP200Page(w, base("Edit"+hyphaName, templates.EditHTML(hyphaName, textAreaFill, warning))) } // handlerUploadText uploads a new text part for the hypha. diff --git a/http_readers.go b/http_readers.go index 34a7146..f288210 100644 --- a/http_readers.go +++ b/http_readers.go @@ -11,7 +11,9 @@ import ( "github.com/bouncepaw/mycorrhiza/gemtext" "github.com/bouncepaw/mycorrhiza/history" + "github.com/bouncepaw/mycorrhiza/templates" "github.com/bouncepaw/mycorrhiza/tree" + "github.com/bouncepaw/mycorrhiza/util" ) func init() { @@ -36,35 +38,16 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) { if err == nil { contents = gemtext.ToHtml(hyphaName, textContents) } - form := fmt.Sprintf(` -
- -
-

Please note that viewing binary parts of hyphae is not supported in history for now.

- %[2]s - %[3]s -
-
- -
-`, hyphaName, + page := templates.RevisionHTML( + hyphaName, naviTitle(hyphaName), contents, tree.TreeAsHtml(hyphaName, IterateHyphaNamesWith), - revHash) + revHash, + ) w.Header().Set("Content-Type", "text/html;charset=utf-8") w.WriteHeader(http.StatusOK) - w.Write([]byte(base(hyphaName, form))) + w.Write([]byte(base(hyphaName, page))) } // handlerHistory lists all revisions of a hypha @@ -82,33 +65,8 @@ func handlerHistory(w http.ResponseWriter, rq *http.Request) { log.Println(revs) } - table := fmt.Sprintf(` -
- - - - - - - - - - - - %[2]s - -
TimeHashUsernameMessage
-
`, hyphaName, tbody) - w.Header().Set("Content-Type", "text/html;charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write([]byte(base(hyphaName, table))) + util.HTTP200Page(w, + base(hyphaName, templates.HistoryHTML(hyphaName, tbody))) } // handlerText serves raw source text of the hypha. @@ -138,8 +96,8 @@ func handlerPage(w http.ResponseWriter, rq *http.Request) { log.Println(rq.URL) var ( hyphaName = HyphaNameFromRq(rq, "page") - contents = fmt.Sprintf(`

This hypha has no text. Why not create it?

`, hyphaName) data, hyphaExists = HyphaStorage[hyphaName] + contents string ) if hyphaExists { fileContentsT, errT := ioutil.ReadFile(data.textPath) @@ -151,38 +109,8 @@ func handlerPage(w http.ResponseWriter, rq *http.Request) { contents = binaryHtmlBlock(hyphaName, data) + contents } } - form := fmt.Sprintf(` -
- -
- %[2]s - %[3]s -
-
-
- -
- - -
-
- -
-`, hyphaName, + util.HTTP200Page(w, base(hyphaName, templates.PageHTML(hyphaName, naviTitle(hyphaName), contents, - tree.TreeAsHtml(hyphaName, IterateHyphaNamesWith)) - w.Header().Set("Content-Type", "text/html;charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write([]byte(base(hyphaName, form))) + tree.TreeAsHtml(hyphaName, IterateHyphaNamesWith)))) } diff --git a/main.go b/main.go index 04acaad..cf567eb 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,5 @@ +//go:generate go get -u github.com/valyala/quicktemplate/qtc +//go:generate qtc -dir=templates package main import ( @@ -9,6 +11,7 @@ import ( "regexp" "github.com/bouncepaw/mycorrhiza/history" + "github.com/bouncepaw/mycorrhiza/templates" "github.com/bouncepaw/mycorrhiza/util" ) @@ -38,29 +41,13 @@ func HttpErr(w http.ResponseWriter, status int, name, title, errMsg string) { errMsg, name))) } -// shorterPath is used by handlerList to display shorter path to the files. It simply strips WikiDir. It was moved to util package, this is an alias. TODO: demolish. -var shorterPath = util.ShorterPath - // Show all hyphae func handlerList(w http.ResponseWriter, rq *http.Request) { log.Println(rq.URL) - w.Header().Set("Content-Type", "text/html;charset=utf-8") - w.WriteHeader(http.StatusOK) - buf := ` -

List of pages

- - - - - - - - - - - ` + var tbody string + // It should be moved to templates too, right? for name, data := range HyphaStorage { - buf += fmt.Sprintf(` + tbody += fmt.Sprintf(` @@ -69,33 +56,15 @@ func handlerList(w http.ResponseWriter, rq *http.Request) { `, name, name, - shorterPath(data.textPath), data.textType, - shorterPath(data.binaryPath), data.binaryType, + util.ShorterPath(data.textPath), data.textType, + util.ShorterPath(data.binaryPath), data.binaryType, ) } - buf += ` - -
NameText pathText typeBinary pathBinary type
%s %s%d
-` - w.Write([]byte(base("List of pages", buf))) + util.HTTP200Page(w, base("List of pages", templates.PageListHTML(tbody))) } // This part is present in all html documents. -func base(title, body string) string { - return fmt.Sprintf(` - - - - - - %s - - - %s - - -`, title, body) -} +var base = templates.BaseHTML // Reindex all hyphae by checking the wiki storage directory anew. func handlerReindex(w http.ResponseWriter, rq *http.Request) { diff --git a/metarrhiza b/metarrhiza index 2a36350..ce6ffcd 160000 --- a/metarrhiza +++ b/metarrhiza @@ -1 +1 @@ -Subproject commit 2a36350d4248610d7e09119d03a602414252abe4 +Subproject commit ce6ffcdb83be6d5d5d15f0a8d240db5430889d45 diff --git a/templates/http_mutators.qtpl b/templates/http_mutators.qtpl new file mode 100644 index 0000000..72f40a1 --- /dev/null +++ b/templates/http_mutators.qtpl @@ -0,0 +1,14 @@ + +{% func EditHTML(hyphaName, textAreaFill, warning string) %} +
+

Edit {%s hyphaName %}

+ {%s= warning %} +
+ +
+ + Cancel +
+
+{% endfunc %} diff --git a/templates/http_mutators.qtpl.go b/templates/http_mutators.qtpl.go new file mode 100644 index 0000000..0c880ea --- /dev/null +++ b/templates/http_mutators.qtpl.go @@ -0,0 +1,83 @@ +// Code generated by qtc from "http_mutators.qtpl". DO NOT EDIT. +// See https://github.com/valyala/quicktemplate for details. + +//line templates/http_mutators.qtpl:2 +package templates + +//line templates/http_mutators.qtpl:2 +import ( + qtio422016 "io" + + qt422016 "github.com/valyala/quicktemplate" +) + +//line templates/http_mutators.qtpl:2 +var ( + _ = qtio422016.Copy + _ = qt422016.AcquireByteBuffer +) + +//line templates/http_mutators.qtpl:2 +func StreamEditHTML(qw422016 *qt422016.Writer, hyphaName, textAreaFill, warning string) { +//line templates/http_mutators.qtpl:2 + qw422016.N().S(` +
+

Edit `) +//line templates/http_mutators.qtpl:4 + qw422016.E().S(hyphaName) +//line templates/http_mutators.qtpl:4 + qw422016.N().S(`

+ `) +//line templates/http_mutators.qtpl:5 + qw422016.N().S(warning) +//line templates/http_mutators.qtpl:5 + qw422016.N().S(` +
+ +
+ + Cancel +
+
+`) +//line templates/http_mutators.qtpl:14 +} + +//line templates/http_mutators.qtpl:14 +func WriteEditHTML(qq422016 qtio422016.Writer, hyphaName, textAreaFill, warning string) { +//line templates/http_mutators.qtpl:14 + qw422016 := qt422016.AcquireWriter(qq422016) +//line templates/http_mutators.qtpl:14 + StreamEditHTML(qw422016, hyphaName, textAreaFill, warning) +//line templates/http_mutators.qtpl:14 + qt422016.ReleaseWriter(qw422016) +//line templates/http_mutators.qtpl:14 +} + +//line templates/http_mutators.qtpl:14 +func EditHTML(hyphaName, textAreaFill, warning string) string { +//line templates/http_mutators.qtpl:14 + qb422016 := qt422016.AcquireByteBuffer() +//line templates/http_mutators.qtpl:14 + WriteEditHTML(qb422016, hyphaName, textAreaFill, warning) +//line templates/http_mutators.qtpl:14 + qs422016 := string(qb422016.B) +//line templates/http_mutators.qtpl:14 + qt422016.ReleaseByteBuffer(qb422016) +//line templates/http_mutators.qtpl:14 + return qs422016 +//line templates/http_mutators.qtpl:14 +} diff --git a/templates/http_readers.qtpl b/templates/http_readers.qtpl new file mode 100644 index 0000000..0c3b4ea --- /dev/null +++ b/templates/http_readers.qtpl @@ -0,0 +1,81 @@ +{% func HistoryHTML(hyphaName, tbody string) %} +
+ + + + + + + + + + + {%s= tbody %} + +
TimeHashMessage
+
+{% endfunc %} + +{% func RevisionHTML(hyphaName, naviTitle, contents, tree, revHash string) %} +
+ +
+

Please note that viewing binary parts of hyphae is not supported in history for now.

+ {%s= naviTitle %} + {%s= contents %} +
+
+ +
+{% endfunc %} + +If `contents` == "", a helpful message is shown instead. +{% func PageHTML(hyphaName, naviTitle, contents, tree string) %} +
+ +
+ {%s= naviTitle %} + {% if contents == "" %} +

This hypha has no text. Why not create it?

+ {% else %} + {%s= contents %} + {% endif %} +
+
+
+ +
+ + +
+
+ +
+{% endfunc %} diff --git a/templates/http_readers.qtpl.go b/templates/http_readers.qtpl.go new file mode 100644 index 0000000..97d4a0b --- /dev/null +++ b/templates/http_readers.qtpl.go @@ -0,0 +1,286 @@ +// Code generated by qtc from "http_readers.qtpl". DO NOT EDIT. +// See https://github.com/valyala/quicktemplate for details. + +//line templates/http_readers.qtpl:1 +package templates + +//line templates/http_readers.qtpl:1 +import ( + qtio422016 "io" + + qt422016 "github.com/valyala/quicktemplate" +) + +//line templates/http_readers.qtpl:1 +var ( + _ = qtio422016.Copy + _ = qt422016.AcquireByteBuffer +) + +//line templates/http_readers.qtpl:1 +func StreamHistoryHTML(qw422016 *qt422016.Writer, hyphaName, tbody string) { +//line templates/http_readers.qtpl:1 + qw422016.N().S(` +
+ + + + + + + + + + + `) +//line templates/http_readers.qtpl:20 + qw422016.N().S(tbody) +//line templates/http_readers.qtpl:20 + qw422016.N().S(` + +
TimeHashMessage
+
+`) +//line templates/http_readers.qtpl:24 +} + +//line templates/http_readers.qtpl:24 +func WriteHistoryHTML(qq422016 qtio422016.Writer, hyphaName, tbody string) { +//line templates/http_readers.qtpl:24 + qw422016 := qt422016.AcquireWriter(qq422016) +//line templates/http_readers.qtpl:24 + StreamHistoryHTML(qw422016, hyphaName, tbody) +//line templates/http_readers.qtpl:24 + qt422016.ReleaseWriter(qw422016) +//line templates/http_readers.qtpl:24 +} + +//line templates/http_readers.qtpl:24 +func HistoryHTML(hyphaName, tbody string) string { +//line templates/http_readers.qtpl:24 + qb422016 := qt422016.AcquireByteBuffer() +//line templates/http_readers.qtpl:24 + WriteHistoryHTML(qb422016, hyphaName, tbody) +//line templates/http_readers.qtpl:24 + qs422016 := string(qb422016.B) +//line templates/http_readers.qtpl:24 + qt422016.ReleaseByteBuffer(qb422016) +//line templates/http_readers.qtpl:24 + return qs422016 +//line templates/http_readers.qtpl:24 +} + +//line templates/http_readers.qtpl:26 +func StreamRevisionHTML(qw422016 *qt422016.Writer, hyphaName, naviTitle, contents, tree, revHash string) { +//line templates/http_readers.qtpl:26 + qw422016.N().S(` +
+ +
+

Please note that viewing binary parts of hyphae is not supported in history for now.

+ `) +//line templates/http_readers.qtpl:39 + qw422016.N().S(naviTitle) +//line templates/http_readers.qtpl:39 + qw422016.N().S(` + `) +//line templates/http_readers.qtpl:40 + qw422016.N().S(contents) +//line templates/http_readers.qtpl:40 + qw422016.N().S(` +
+
+ +
+`) +//line templates/http_readers.qtpl:47 +} + +//line templates/http_readers.qtpl:47 +func WriteRevisionHTML(qq422016 qtio422016.Writer, hyphaName, naviTitle, contents, tree, revHash string) { +//line templates/http_readers.qtpl:47 + qw422016 := qt422016.AcquireWriter(qq422016) +//line templates/http_readers.qtpl:47 + StreamRevisionHTML(qw422016, hyphaName, naviTitle, contents, tree, revHash) +//line templates/http_readers.qtpl:47 + qt422016.ReleaseWriter(qw422016) +//line templates/http_readers.qtpl:47 +} + +//line templates/http_readers.qtpl:47 +func RevisionHTML(hyphaName, naviTitle, contents, tree, revHash string) string { +//line templates/http_readers.qtpl:47 + qb422016 := qt422016.AcquireByteBuffer() +//line templates/http_readers.qtpl:47 + WriteRevisionHTML(qb422016, hyphaName, naviTitle, contents, tree, revHash) +//line templates/http_readers.qtpl:47 + qs422016 := string(qb422016.B) +//line templates/http_readers.qtpl:47 + qt422016.ReleaseByteBuffer(qb422016) +//line templates/http_readers.qtpl:47 + return qs422016 +//line templates/http_readers.qtpl:47 +} + +// If `contents` == "", a helpful message is shown instead. + +//line templates/http_readers.qtpl:50 +func StreamPageHTML(qw422016 *qt422016.Writer, hyphaName, naviTitle, contents, tree string) { +//line templates/http_readers.qtpl:50 + qw422016.N().S(` +
+ +
+ `) +//line templates/http_readers.qtpl:61 + qw422016.N().S(naviTitle) +//line templates/http_readers.qtpl:61 + qw422016.N().S(` + `) +//line templates/http_readers.qtpl:62 + if contents == "" { +//line templates/http_readers.qtpl:62 + qw422016.N().S(` +

This hypha has no text. Why not create it?

+ `) +//line templates/http_readers.qtpl:64 + } else { +//line templates/http_readers.qtpl:64 + qw422016.N().S(` + `) +//line templates/http_readers.qtpl:65 + qw422016.N().S(contents) +//line templates/http_readers.qtpl:65 + qw422016.N().S(` + `) +//line templates/http_readers.qtpl:66 + } +//line templates/http_readers.qtpl:66 + qw422016.N().S(` +
+
+
+ +
+ + +
+
+ +
+`) +//line templates/http_readers.qtpl:81 +} + +//line templates/http_readers.qtpl:81 +func WritePageHTML(qq422016 qtio422016.Writer, hyphaName, naviTitle, contents, tree string) { +//line templates/http_readers.qtpl:81 + qw422016 := qt422016.AcquireWriter(qq422016) +//line templates/http_readers.qtpl:81 + StreamPageHTML(qw422016, hyphaName, naviTitle, contents, tree) +//line templates/http_readers.qtpl:81 + qt422016.ReleaseWriter(qw422016) +//line templates/http_readers.qtpl:81 +} + +//line templates/http_readers.qtpl:81 +func PageHTML(hyphaName, naviTitle, contents, tree string) string { +//line templates/http_readers.qtpl:81 + qb422016 := qt422016.AcquireByteBuffer() +//line templates/http_readers.qtpl:81 + WritePageHTML(qb422016, hyphaName, naviTitle, contents, tree) +//line templates/http_readers.qtpl:81 + qs422016 := string(qb422016.B) +//line templates/http_readers.qtpl:81 + qt422016.ReleaseByteBuffer(qb422016) +//line templates/http_readers.qtpl:81 + return qs422016 +//line templates/http_readers.qtpl:81 +} diff --git a/templates/http_stuff.qtpl b/templates/http_stuff.qtpl new file mode 100644 index 0000000..63a3a4e --- /dev/null +++ b/templates/http_stuff.qtpl @@ -0,0 +1,33 @@ +{% func BaseHTML(title, body string) %} + + + + + + {%s title %} + + + {%s= body %} + + +{% endfunc %} + +{% func PageListHTML(tbody string) %} +
+

List of pages

+ + + + + + + + + + + + {%s= tbody %} + +
NameText pathText typeBinary pathBinary type
+
+{% endfunc %} diff --git a/templates/http_stuff.qtpl.go b/templates/http_stuff.qtpl.go new file mode 100644 index 0000000..89d322c --- /dev/null +++ b/templates/http_stuff.qtpl.go @@ -0,0 +1,126 @@ +// Code generated by qtc from "http_stuff.qtpl". DO NOT EDIT. +// See https://github.com/valyala/quicktemplate for details. + +//line templates/http_stuff.qtpl:1 +package templates + +//line templates/http_stuff.qtpl:1 +import ( + qtio422016 "io" + + qt422016 "github.com/valyala/quicktemplate" +) + +//line templates/http_stuff.qtpl:1 +var ( + _ = qtio422016.Copy + _ = qt422016.AcquireByteBuffer +) + +//line templates/http_stuff.qtpl:1 +func StreamBaseHTML(qw422016 *qt422016.Writer, title, body string) { +//line templates/http_stuff.qtpl:1 + qw422016.N().S(` + + + + + + `) +//line templates/http_stuff.qtpl:7 + qw422016.E().S(title) +//line templates/http_stuff.qtpl:7 + qw422016.N().S(` + + + `) +//line templates/http_stuff.qtpl:10 + qw422016.N().S(body) +//line templates/http_stuff.qtpl:10 + qw422016.N().S(` + + +`) +//line templates/http_stuff.qtpl:13 +} + +//line templates/http_stuff.qtpl:13 +func WriteBaseHTML(qq422016 qtio422016.Writer, title, body string) { +//line templates/http_stuff.qtpl:13 + qw422016 := qt422016.AcquireWriter(qq422016) +//line templates/http_stuff.qtpl:13 + StreamBaseHTML(qw422016, title, body) +//line templates/http_stuff.qtpl:13 + qt422016.ReleaseWriter(qw422016) +//line templates/http_stuff.qtpl:13 +} + +//line templates/http_stuff.qtpl:13 +func BaseHTML(title, body string) string { +//line templates/http_stuff.qtpl:13 + qb422016 := qt422016.AcquireByteBuffer() +//line templates/http_stuff.qtpl:13 + WriteBaseHTML(qb422016, title, body) +//line templates/http_stuff.qtpl:13 + qs422016 := string(qb422016.B) +//line templates/http_stuff.qtpl:13 + qt422016.ReleaseByteBuffer(qb422016) +//line templates/http_stuff.qtpl:13 + return qs422016 +//line templates/http_stuff.qtpl:13 +} + +//line templates/http_stuff.qtpl:15 +func StreamPageListHTML(qw422016 *qt422016.Writer, tbody string) { +//line templates/http_stuff.qtpl:15 + qw422016.N().S(` +
+

List of pages

+ + + + + + + + + + + + `) +//line templates/http_stuff.qtpl:29 + qw422016.N().S(tbody) +//line templates/http_stuff.qtpl:29 + qw422016.N().S(` + +
NameText pathText typeBinary pathBinary type
+
+`) +//line templates/http_stuff.qtpl:33 +} + +//line templates/http_stuff.qtpl:33 +func WritePageListHTML(qq422016 qtio422016.Writer, tbody string) { +//line templates/http_stuff.qtpl:33 + qw422016 := qt422016.AcquireWriter(qq422016) +//line templates/http_stuff.qtpl:33 + StreamPageListHTML(qw422016, tbody) +//line templates/http_stuff.qtpl:33 + qt422016.ReleaseWriter(qw422016) +//line templates/http_stuff.qtpl:33 +} + +//line templates/http_stuff.qtpl:33 +func PageListHTML(tbody string) string { +//line templates/http_stuff.qtpl:33 + qb422016 := qt422016.AcquireByteBuffer() +//line templates/http_stuff.qtpl:33 + WritePageListHTML(qb422016, tbody) +//line templates/http_stuff.qtpl:33 + qs422016 := string(qb422016.B) +//line templates/http_stuff.qtpl:33 + qt422016.ReleaseByteBuffer(qb422016) +//line templates/http_stuff.qtpl:33 + return qs422016 +//line templates/http_stuff.qtpl:33 +} diff --git a/util/util.go b/util/util.go index f45ef9a..ee77e07 100644 --- a/util/util.go +++ b/util/util.go @@ -1,6 +1,7 @@ package util import ( + "net/http" "strings" ) @@ -17,3 +18,10 @@ func ShorterPath(path string) string { } return path } + +// HTTP200Page wraps some frequently used things for successful 200 responses. +func HTTP200Page(w http.ResponseWriter, page string) { + w.Header().Set("Content-Type", "text/html;charset=utf-8") + w.WriteHeader(http.StatusOK) + w.Write([]byte(page)) +}