From 259ce77cdc8bf9655578cb55bbc6c27fe89cfd9f Mon Sep 17 00:00:00 2001 From: Will Norris Date: Tue, 7 Jun 2022 13:49:29 -0700 Subject: [PATCH] cmd/golink: move home template into separate file This sets up an embed.FS even though we only have the one file right now, as we will have more shortly. Change-Id: I1292e4c00602fbfc3a7bc2a5f93a8c9b9e6715c0 --- golink.go | 23 +++++------------------ home.html | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 home.html diff --git a/golink.go b/golink.go index c4b005c..44fe1d4 100644 --- a/golink.go +++ b/golink.go @@ -4,6 +4,7 @@ package main import ( "bufio" "bytes" + "embed" _ "embed" "encoding/json" "flag" @@ -41,6 +42,9 @@ var stats struct { //go:embed link-snapshot.json var lastSnapshot []byte +//go:embed *.html +var embeddedFS embed.FS + var localClient *tailscale.LocalClient // DiskLink is the JSON structure stored on disk in a file for each go short link. @@ -126,24 +130,7 @@ type homeData struct { } func init() { - homeCreate = template.Must(template.New("home").Parse(` - -

go/

-shortlink service. - -

create

-
-http://go/ ==> -
- -

recent popular links

- - -{{range .Clicks}} - -{{end}} -
short linknum clicks
http://go/{{.Short}}{{.NumClicks}}
-`)) + homeCreate = template.Must(template.ParseFS(embeddedFS, "home.html")) } func linkPath(short string) string { diff --git a/home.html b/home.html new file mode 100644 index 0000000..df1df0f --- /dev/null +++ b/home.html @@ -0,0 +1,17 @@ + + +

go/

+shortlink service. + +

create

+
+http://go/ ==> +
+ +

recent popular links

+ + +{{range .Clicks}} + +{{end}} +
short linknum clicks
http://go/{{.Short}}{{.NumClicks}}