cmd/relui: use go:embed for templates and content
This changes relui to use embed from go1.16 for managing content. This
drastically simplifies the deployment steps, in preparation for
containerizing.
For golang/go#47401
Change-Id: I1eb9f6f63fa490ef73ed454ddecd1fd99db4f960
Reviewed-on: https://go-review.googlesource.com/c/build/+/340429
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/cmd/relui/web_test.go b/cmd/relui/web_test.go
index 145ad5b..dcd18e6 100644
--- a/cmd/relui/web_test.go
+++ b/cmd/relui/web_test.go
@@ -2,10 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+//go:build go1.16
+// +build go1.16
+
package main
import (
"context"
+ "embed"
"io/ioutil"
"net/http"
"net/http/httptest"
@@ -21,8 +25,12 @@
"google.golang.org/grpc"
)
+// testStatic is our static web server content.
+//go:embed testing
+var testStatic embed.FS
+
func TestFileServerHandler(t *testing.T) {
- h := fileServerHandler("./testing", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ h := fileServerHandler(testStatic, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Home"))
}))
@@ -41,7 +49,7 @@
},
{
desc: "sets headers and returns file",
- path: "/test.css",
+ path: "/testing/test.css",
wantCode: http.StatusOK,
wantBody: ".Header { font-size: 10rem; }\n",
wantHeaders: map[string]string{
@@ -54,6 +62,9 @@
path: "/foo.js",
wantCode: http.StatusNotFound,
wantBody: "404 page not found\n",
+ wantHeaders: map[string]string{
+ "Content-Type": "text/plain; charset=utf-8",
+ },
},
}
for _, c := range cases {