-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
31 lines (23 loc) · 727 Bytes
/
main.go
File metadata and controls
31 lines (23 loc) · 727 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
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func newRouter() *mux.Router {
router := mux.NewRouter()
staticFileDirectory := http.Dir("./assets/")
staticFileHandler := http.StripPrefix("/assets/", http.FileServer(staticFileDirectory))
router.PathPrefix("/assets/").Handler(staticFileHandler).Methods("GET")
router.HandleFunc("/welcome", handler).Methods("GET")
router.HandleFunc("/bird", getBirdHandler).Methods("GET")
router.HandleFunc("/bird", createBirdHandler).Methods("POST")
return router
}
func main() {
router := newRouter()
http.ListenAndServe(":8080", router)
}
func handler(writer http.ResponseWriter, reader *http.Request) {
fmt.Fprintf(writer, "Welcome to Birdpedia!")
}