From 2e4b06c59582b6128ca8299f1a4e6572f78ca60d Mon Sep 17 00:00:00 2001 From: Fabricio Date: Wed, 24 Feb 2021 08:49:00 -0300 Subject: [PATCH] refactor: embed html --- .github/workflows/build.yml | 4 +- dashboard.go | 327 --------------------------- dashboard.html | 427 ++++++++++++++++++++++++++++++++++++ go.mod | 2 +- main.go | 6 +- 5 files changed, 435 insertions(+), 331 deletions(-) delete mode 100644 dashboard.go create mode 100644 dashboard.html diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ecced5..1a2da0a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,10 +7,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.16 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.16 id: go - name: Check out code into the Go module directory diff --git a/dashboard.go b/dashboard.go deleted file mode 100644 index f5323f2..0000000 --- a/dashboard.go +++ /dev/null @@ -1,327 +0,0 @@ -package main - -const dashboardHTML = ` - - - - - - - - - Dashboard - - - - -
- -
-
- -
-
-
- {{item.method}} - ‎{{item.path}}‎ - {{item.elapsed}}ms - {{item.status == 999 ? 'failed' : item.status}} -
-
-
- -
-
- - - -
-
-
req
-
{{selectedItem.request}}
-
-
- -
-
- -
-
-
res
-
{{selectedItem.response}}
-
-
- -
-

Waiting for requests on http://localhost:<<.ProxyPort>>/
- Proxying <<.TargetURL>>

-
- -
- - - -` diff --git a/dashboard.html b/dashboard.html new file mode 100644 index 0000000..f594a2a --- /dev/null +++ b/dashboard.html @@ -0,0 +1,427 @@ + + + + + + + + + + Dashboard + + + + + +
+ +
+
+ +
+
+
+ {{item.method}} + ‎{{item.path}}‎ + {{item.elapsed}}ms + {{item.status == 999 ? 'failed' : + item.status}} +
+
+
+ +
+
+ + + +
+
+
req
+
{{selectedItem.request}}
+
+
+ +
+
+ +
+
+
res
+
{{selectedItem.response}}
+
+
+ +
+

Waiting for requests on http://localhost:{{{.ProxyPort}}}/
+ Proxying {{{.TargetURL}}} +

+
+ +
+ + + + + \ No newline at end of file diff --git a/go.mod b/go.mod index fb89bec..d33b670 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/ofabricio/capture -go 1.13 +go 1.16 diff --git a/main.go b/main.go index 9f6fb1a..3806845 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" "compress/gzip" + _ "embed" "encoding/json" "fmt" "html/template" @@ -24,6 +25,9 @@ import ( // StatusInternalProxyError is any unknown proxy error const StatusInternalProxyError = 999 +//go:embed dashboard.html +var dashboardHTML string + func main() { cfg := ReadConfig() @@ -88,7 +92,7 @@ func NewDashboardClearHandler(srv *CaptureService) http.HandlerFunc { func NewDashboardHTMLHandler(config Config) http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { rw.Header().Add("Content-Type", "text/html") - t, err := template.New("dashboard template").Delims("<<", ">>").Parse(dashboardHTML) + t, err := template.New("dashboard template").Delims("{{{", "}}}").Parse(dashboardHTML) if err != nil { msg := fmt.Sprintf("could not parse dashboard html template: %v", err) fmt.Println(msg)