initial commit on github
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func RegisterGroupsRoutes(r *mux.Router) {
|
||||
r.HandleFunc("/groups", resolveGroups).Methods("GET", "OPTIONS", "POST")
|
||||
r.HandleFunc("/groups/{id:[0-9]+}", resolveGroup).Methods("GET", "OPTIONS", "PUT", "DELETE")
|
||||
}
|
||||
|
||||
func resolveGroups(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
groups, err := GetGroups()
|
||||
Response(w, err, groups)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func resolveGroup(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
id, _ := strconv.Atoi(vars["id"])
|
||||
|
||||
if r.Method == http.MethodGet {
|
||||
group, err := GetGroup(id)
|
||||
Response(w, err, group)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user