-
Notifications
You must be signed in to change notification settings - Fork 0
/
articles.go
46 lines (34 loc) · 1.14 KB
/
articles.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"net/http"
"github.com/go-chi/chi"
)
type articlesResource struct{}
func (rs articlesResource) Routes() chi.Router {
r := chi.NewRouter()
// r.Use(...) // apply routes Middleware
r.Get("/", rs.List) // GET /articles
r.Post("/", rs.Create) // POST /articles
r.Route("/{id}", func(r chi.Router) {
// r.Use(...) // apply routes Middleware
r.Get("/", rs.Get) // GET /articles/{id}
r.Put("/", rs.Update) // PUT /articles/{id}
r.Delete("/", rs.Delete) // DELETE /articles/{id}
})
return r
}
func (rs articlesResource) List(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("List of Articles."))
}
func (rs articlesResource) Create(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Create a New Article."))
}
func (rs articlesResource) Get(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Get a Article by ID."))
}
func (rs articlesResource) Update(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Update a Article by ID."))
}
func (rs articlesResource) Delete(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Delete a Article by ID."))
}