mirror of
https://github.com/wahyd4/golink.git
synced 2026-08-09 05:05:56 +10:00
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
This commit is contained in:
@@ -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(`<html>
|
||||
<body>
|
||||
<h1>go/</h1>
|
||||
shortlink service.
|
||||
|
||||
<h2>create</h2>
|
||||
<form method="POST" action="/">
|
||||
http://go/<input name=short size=20 value="{{.Short}}"> ==> <input name=long size=40> <input type=submit value="create">
|
||||
</form>
|
||||
|
||||
<h2>recent popular links</h2>
|
||||
<table>
|
||||
<tr><th>short link</th><th>num clicks</th></tr>
|
||||
{{range .Clicks}}
|
||||
<tr><td><a href="http://go/{{.Short}}">http://go/{{.Short}}</a></td><td>{{.NumClicks}}</td></tr>
|
||||
{{end}}
|
||||
</table>
|
||||
`))
|
||||
homeCreate = template.Must(template.ParseFS(embeddedFS, "home.html"))
|
||||
}
|
||||
|
||||
func linkPath(short string) string {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>go/</h1>
|
||||
shortlink service.
|
||||
|
||||
<h2>create</h2>
|
||||
<form method="POST" action="/">
|
||||
http://go/<input name=short size=20 value="{{.Short}}"> ==> <input name=long size=40> <input type=submit value="create">
|
||||
</form>
|
||||
|
||||
<h2>recent popular links</h2>
|
||||
<table>
|
||||
<tr><th>short link</th><th>num clicks</th></tr>
|
||||
{{range .Clicks}}
|
||||
<tr><td><a href="http://go/{{.Short}}">http://go/{{.Short}}</a></td><td>{{.NumClicks}}</td></tr>
|
||||
{{end}}
|
||||
</table>
|
||||
Reference in New Issue
Block a user