-
Notifications
You must be signed in to change notification settings - Fork 0
/
home_page_handler.go
84 lines (77 loc) · 2.21 KB
/
home_page_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"html/template"
"math/rand"
"net/http"
)
type HomePage struct {
Stylesheet template.HTML
Cachebuster int
}
var homePageTemplate string = `
<!DOCTYPE html>
<html lang="en">
<head>
<title>Frontend</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{.Stylesheet}}
</head>
<body>
<div class="container">
<div class="header clearfix navbar navbar-inverse">
<div class="container">
<h3>Frontend Sample App</h3>
</div>
</div>
<div class="jumbotron">
<form action="/proxy/" method="get" class="form-inline">
<div class="row">
<h2>HTTP Test</h2>
<div class=".col-md-4.col-md-offset-4">
<div class="form-group">
<label for="url">Backend HTTP URL</label>
<input type="text" name="url" class="form-control" placeholder="127.0.0.1:8080">
</div>
<input type="hidden" name="cachebuster" value="{{.Cachebuster}}">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
<div class="jumbotron">
<form action="/udp-test/" method="get" class="form-inline">
<div class="row">
<h2>UDP Test</h2>
<div class=".col-md-4.col-md-offset-4">
<div class="form-group">
<label for="url">Backend UDP Server Address</label>
<input type="text" name="url" class="form-control" placeholder="127.0.0.1:9001">
</div>
<br>
<div class="form-group">
<label for="message">Message</label>
<input type="text" name="message" class="form-control" placeholder="hello world">
</div>
<input type="hidden" name="cachebuster" value="{{.Cachebuster}}">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
`
type HomePageHandler struct{}
func (h *HomePageHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
template := template.Must(template.New("homePage").Parse(homePageTemplate))
err := template.Execute(resp, HomePage{
Stylesheet: stylesheet,
Cachebuster: rand.Int(),
})
if err != nil {
panic(err)
}
}