forked from ardanlabs/gotraining
/
routes.go
27 lines (21 loc) · 805 Bytes
/
routes.go
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
package routes
import (
"net/http"
"github.com/ardanlabs/gotraining/topics/http/api/app"
"github.com/ardanlabs/gotraining/topics/http/api/handlers"
)
// API returns a handler for a set of routes.
func API() http.Handler {
a := app.New()
// Setup the file server to serve up static content such as
// the index.html page.
a.TreeMux.NotFoundHandler = http.FileServer(http.Dir("views")).ServeHTTP
// Initialize the routes for the API binding the route to the
// handler code for each specified verb.
a.Handle("GET", "/v1/users", handlers.Users.List)
a.Handle("POST", "/v1/users", handlers.Users.Create)
a.Handle("GET", "/v1/users/:id", handlers.Users.Retrieve)
a.Handle("PUT", "/v1/users/:id", handlers.Users.Update)
a.Handle("DELETE", "/v1/users/:id", handlers.Users.Delete)
return a
}