FILE / Unmei/Backend

v1/groups_routes.go

Исходный файл и его история в репозитории.
FILE 7babade475dea45e22941afa4f10e7cd0ea64934
Files
Backend/v1/groups_routes.go
T
2021-05-02 16:04:45 +03:00

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)
}
}