mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-04 14:41:01 +00:00
cmd/hello: use go:embed for the template
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
9df4185c94
commit
b46e337cdc
@ -7,6 +7,7 @@ package main // import "tailscale.com/cmd/hello"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -30,6 +31,9 @@ var (
|
|||||||
testIP = flag.String("test-ip", "", "if non-empty, look up IP and exit before running a server")
|
testIP = flag.String("test-ip", "", "if non-empty, look up IP and exit before running a server")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed hello.tmpl.html
|
||||||
|
var embeddedTemplate string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *testIP != "" {
|
if *testIP != "" {
|
||||||
@ -43,7 +47,10 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !devMode() {
|
if !devMode() {
|
||||||
tmpl = template.Must(template.New("home").Parse(slurpHTML()))
|
if embeddedTemplate == "" {
|
||||||
|
log.Fatalf("embeddedTemplate is empty; must be build with Go 1.16+")
|
||||||
|
}
|
||||||
|
tmpl = template.Must(template.New("home").Parse(embeddedTemplate))
|
||||||
}
|
}
|
||||||
|
|
||||||
http.HandleFunc("/", root)
|
http.HandleFunc("/", root)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user