Skip to content

Commit 4995cc5

Browse files
committed
Added gorilla/mux
1 parent d45fc80 commit 4995cc5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

main.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ package main
33
import (
44
"fmt"
55
"net/http"
6+
"github.com/gorilla/mux"
67
)
78

8-
func handler(w http.ResponseWriter, r *http.Request) {
9+
func main() {
10+
r := mux.NewRouter()
11+
r.HandleFunc("/hello", helloHandler).Methods("GET")
12+
r.HandleFunc("/goodbye", goodbyeHandler).Methods("GET")
13+
http.Handle("/", r)
14+
http.ListenAndServe(":8080", nil)
15+
}
16+
17+
func helloHandler(w http.ResponseWriter, r *http.Request) {
918
fmt.Fprint(w, "Hello world!")
1019
}
1120

12-
func main() {
13-
http.HandleFunc("/", handler)
14-
http.ListenAndServe(":8080", nil)
21+
func goodbyeHandler(w http.ResponseWriter, r *http.Request) {
22+
fmt.Fprint(w, "Goodbye world!")
1523
}

0 commit comments

Comments
 (0)