-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (33 loc) · 1001 Bytes
/
Copy pathmain.go
File metadata and controls
40 lines (33 loc) · 1001 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"
"github.com/gorilla/mux"
)
func home(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, "<h1>Welcome to my awesome site!</h1>")
}
func contact(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, "To get in touch, please send an email "+
"to <a href=\"mailto:support@test.test\">"+
"support@test.test</a>.")
}
func faq(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, "This is a nice faq page!")
}
func sorry(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, "<h1>I'm afraid i can't do that for you dave... ):")
}
func main() {
var nf http.Handler = http.HandlerFunc(sorry)
r := mux.NewRouter()
r.NotFoundHandler = nf
r.HandleFunc("/", home)
r.HandleFunc("/contact", contact)
r.HandleFunc("/faq", faq)
http.ListenAndServe(":3000", r)
}