-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (27 loc) · 674 Bytes
/
Copy pathmain.go
File metadata and controls
37 lines (27 loc) · 674 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
package main
// based on http://thenewstack.io/building-a-web-server-in-go/
import (
"io"
"net/http"
)
func demo(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "The demo works!")
}
var mux map[string]func(http.ResponseWriter, *http.Request)
func main() {
server := http.Server{
Addr: ":80",
Handler: &myHandler{},
}
mux = make(map[string]func(http.ResponseWriter, *http.Request))
mux["/"] = demo
server.ListenAndServe()
}
type myHandler struct{}
func (*myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if h, ok := mux[r.URL.String()]; ok {
h(w, r)
return
}
io.WriteString(w, "This page intentionally left blank")
}