FILE / Unmei/Backend
v1/groups_routes.go
Исходный файл и его история в репозитории.
31 lines
707 B
Go
31 lines
707 B
Go
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)
|
|
}
|
|
} |