diff options
author | 2018-12-31 12:31:52 -0800 | |
---|---|---|
committer | 2019-01-03 11:48:28 -0800 | |
commit | 086cdf873f5fb22f858476a035883a945503bd4a (patch) | |
tree | c0bda7f0e0b46a11b0be4ab72f51e2a7bc318a2a /handler.go | |
parent | fa1cf198a7c22a0f7537c565e36a19567bbde0d8 (diff) | |
download | sally-086cdf873f5fb22f858476a035883a945503bd4a.tar.gz sally-086cdf873f5fb22f858476a035883a945503bd4a.tar.zst sally-086cdf873f5fb22f858476a035883a945503bd4a.zip |
Add minimal styling
Diffstat (limited to 'handler.go')
-rw-r--r-- | handler.go | 39 |
1 files changed, 12 insertions, 27 deletions
@@ -8,6 +8,18 @@ import ( "github.com/julienschmidt/httprouter" ) +var indexTemplate, packageTemplate *template.Template + +func init() { + tmpls := template.Must(template.ParseGlob("templates/*.html")) + if indexTemplate = tmpls.Lookup("index.html"); indexTemplate == nil { + panic("Missing index.html template") + } + if packageTemplate = tmpls.Lookup("package.html"); packageTemplate == nil { + panic("Missing package.html template") + } +} + // CreateHandler creates a Sally http.Handler func CreateHandler(config *Config) http.Handler { router := httprouter.New() @@ -38,19 +50,6 @@ func (h indexHandler) Handle(w http.ResponseWriter, r *http.Request, _ httproute } } -var indexTemplate = template.Must(template.New("index").Parse(` -<!DOCTYPE html> -<html> - <body> - <ul> - {{ range $key, $value := .Packages }} - <li>{{ $key }} - {{ $value.Repo }}</li> - {{ end }} - </ul> - </body> -</html> -`)) - type packageHandler struct { pkgName string pkg Package @@ -72,17 +71,3 @@ func (h packageHandler) Handle(w http.ResponseWriter, r *http.Request, ps httpro http.Error(w, err.Error(), 500) } } - -var packageTemplate = template.Must(template.New("package").Parse(` -<!DOCTYPE html> -<html> - <head> - <meta name="go-import" content="{{ .CanonicalURL }} git https://{{ .Repo }}"> - <meta name="go-source" content="{{ .CanonicalURL }} https://{{ .Repo }} https://{{ .Repo }}/tree/master{/dir} https://{{ .Repo }}/tree/master{/dir}/{file}#L{line}"> - <meta http-equiv="refresh" content="0; url={{ .GodocURL }}"> - </head> - <body> - Nothing to see here. Please <a href="{{ .GodocURL }}">move along</a>. - </body> -</html> -`)) |