-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (32 loc) · 869 Bytes
/
main.go
File metadata and controls
40 lines (32 loc) · 869 Bytes
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
package main
import (
"fmt"
"net/http"
"os"
)
var requests []string
func main() {
port := "8888"
if len(os.Args) > 1 {
port = os.Args[1]
}
fmt.Println("Listening on port: " + port)
http.HandleFunc("/", rootPage)
http.HandleFunc("/record/", fooPage)
http.ListenAndServe(":"+port, nil)
}
func rootPage(writer http.ResponseWriter, request *http.Request) {
fmt.Println("Serving root")
request.ParseForm()
fmt.Fprintln(writer, `<h1>Requests</h1><body><ul>`)
for _, req := range requests {
fmt.Fprintln(writer, `<li>`+req)
}
fmt.Fprintln(writer, `</ul></body>`)
}
func fooPage(writer http.ResponseWriter, request *http.Request) {
request.ParseForm()
requests = append(requests, request.URL.RequestURI())
fmt.Println("Recorded: " + request.URL.RequestURI())
fmt.Fprintln(writer, `<h1>Recorded!</h1><body>`+request.URL.RequestURI()+`</body>`)
}