Skip to content

Commit eba700b

Browse files
authored
Merge pull request #82 from JudahNour/embedHTML
embed html files into go code
2 parents c0abf47 + 2b5a367 commit eba700b

File tree

4 files changed

+48
-38
lines changed

4 files changed

+48
-38
lines changed

cmd/gopogh-server/flake_chart.html

Lines changed: 0 additions & 35 deletions
This file was deleted.

cmd/gopogh-server/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
_ "embed"
45
"flag"
56
"log"
67
"net/http"
@@ -31,6 +32,7 @@ func main() {
3132
Database: datab,
3233
}
3334
// Create an HTTP server and register the handlers
35+
3436
http.HandleFunc("/db", db.ServeEnvironmentTestsAndTestCases)
3537

3638
http.HandleFunc("/env", db.ServeEnvCharts)
@@ -41,6 +43,8 @@ func main() {
4143

4244
http.HandleFunc("/version", handler.ServeGopoghVersion)
4345

46+
http.HandleFunc("/", handler.ServeHTML)
47+
4448
// Start the HTTP server
4549
err = http.ListenAndServe(":8080", nil)
4650
if err != nil {

cmd/gopogh-server/flake_chart.js renamed to pkg/handler/flake_chart.html

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
// Displays an error message to the UI. Any previous message will be erased.
1+
<html>
2+
<head>
3+
<meta http-equiv="CacheControl" content="no-cache, no-store, must-revalidate"/>
4+
<meta http-equiv="Pragma" content="no-cache"/>
5+
<meta http-equiv="Expires" content="0"/>
6+
7+
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
8+
<script src='https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/tablesort.min.js'></script>
9+
<!-- Include sort types you need -->
10+
<script src='https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/sorts/tablesort.number.min.js'></script>
11+
<script type="text/javascript">
12+
// Displays an error message to the UI. Any previous message will be erased.
213
function displayError(message) {
314
// Clear the body of all children.
415
while (document.body.firstChild) {
@@ -862,7 +873,7 @@
862873
await new Promise(resolve => google.charts.setOnLoadCallback(resolve));
863874

864875
let url;
865-
const basePath = 'http://localhost:8080' // Base Server Path. Modify to actual server path if deploying
876+
const basePath = ':8080' // Base Server Path. Modify to actual server path if deploying
866877
if (desiredEnvironment === undefined) {
867878
// URL for displaySummaryChart
868879
url = basePath + '/summary'
@@ -905,4 +916,24 @@
905916
}
906917
}
907918

908-
init();
919+
init();
920+
</script>
921+
<style>
922+
table {
923+
border: 1px solid gray;
924+
margin-left: auto;
925+
margin-right: auto;
926+
border-collapse: collapse;
927+
}
928+
td, th {
929+
border-bottom: 1px solid gray;
930+
padding: 8px;
931+
}
932+
</style>
933+
</head>
934+
<body>
935+
<div id="dropdown_container"></div>
936+
<div id="chart_div"></div>
937+
<div id="version_div"></div>
938+
</body>
939+
</html>

pkg/handler/handler.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package handler
22

33
import (
4+
_ "embed"
45
"encoding/json"
56
"fmt"
67
"net/http"
@@ -14,6 +15,9 @@ type DB struct {
1415
Database db.Datab
1516
}
1617

18+
//go:embed flake_chart.html
19+
var flakeChartHTML string
20+
1721
func (m *DB) ServeEnvironmentTestsAndTestCases(w http.ResponseWriter, _ *http.Request) {
1822
data, err := m.Database.GetEnvironmentTestsAndTestCases()
1923
if err != nil {
@@ -158,3 +162,9 @@ func ServeGopoghVersion(w http.ResponseWriter, _ *http.Request) {
158162
return
159163
}
160164
}
165+
166+
func ServeHTML(w http.ResponseWriter, _ *http.Request) {
167+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
168+
w.Header().Set("Access-Control-Allow-Origin", "*")
169+
fmt.Fprint(w, flakeChartHTML)
170+
}

0 commit comments

Comments
 (0)