diff options
| author | 2019-12-19 13:00:42 -0500 | |
|---|---|---|
| committer | 2019-12-19 13:00:42 -0500 | |
| commit | f2c84ff8e9a0a7d6cf5b7fb63f2a138cccf10dd7 (patch) | |
| tree | 520fae8b7acc2744f94f60410d2a891fd792ddc4 | |
| parent | feat: add docs for the memory backend (diff) | |
feat: make templates overridable compile-time
fixes #5
| -rw-r--r-- | http/get.go | 3 | ||||
| -rw-r--r-- | http/index.go | 3 | ||||
| -rw-r--r-- | http/templates.go | 12 |
3 files changed, 14 insertions, 4 deletions
diff --git a/http/get.go b/http/get.go index 903b5b2..8d3c523 100644 --- a/http/get.go +++ b/http/get.go @@ -3,7 +3,6 @@ package http import ( "github.com/valyala/fasthttp" "toast.cafe/x/brpaste/v2/storage" - "toast.cafe/x/brpaste/v2/template" ) // Get generates a handler for the /:key[/:lang] endpoint @@ -26,7 +25,7 @@ func Get(store storage.CHR) handler { if lang == "raw" { ctx.SuccessString("text/plain", res) } else { - ctx.SuccessString("text/html", template.Code(lang, res)) // render template + ctx.SuccessString("text/html", CodeTemplate(lang, res)) // render template } default: ctx.NotFound() diff --git a/http/index.go b/http/index.go index 792e64a..d9c42f2 100644 --- a/http/index.go +++ b/http/index.go @@ -2,10 +2,9 @@ package http import ( "github.com/valyala/fasthttp" - "toast.cafe/x/brpaste/v2/template" ) // Index handles the / endpoint func Index(ctx *fasthttp.RequestCtx) { - ctx.SuccessString("text/html", template.Index()) // render template + ctx.SuccessString("text/html", IndexTemplate()) // render template } diff --git a/http/templates.go b/http/templates.go new file mode 100644 index 0000000..de5d3dd --- /dev/null +++ b/http/templates.go @@ -0,0 +1,12 @@ +package http + +import "toast.cafe/x/brpaste/v2/template" + +var ( + // CodeTemplate is the function to be used as the template for the code viewer + // overwrite it before calling GenHandler + CodeTemplate = template.Code + // IndexTemplate is the function to be used as the template for the index page + // overwrite it before calling GenHandler + IndexTemplate = template.Index +) |
