go-tsviewer/features/channel/handler.go

41 lines
950 B
Go
Raw Normal View History

2019-01-14 20:07:11 +00:00
package channel
import (
"net/http"
"strconv"
"git.cliffbreak.de/haveachin/go-tsviewer/response"
"github.com/go-chi/chi"
)
2019-01-16 21:01:48 +00:00
func ChannelAPIHandler(s Service) http.HandlerFunc {
2019-01-14 20:07:11 +00:00
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response.Handler(w, response.HandlerFunc(func() (int, error) {
id, err := strconv.ParseUint(chi.URLParam(r, "id"), 10, 64)
if err != nil {
return http.StatusBadRequest, err
}
c, err := s.Channel(int(id))
if err != nil {
return http.StatusNotFound, err
}
return response.New(c, r).Send(w, http.StatusOK)
}))
})
}
2019-01-16 21:01:48 +00:00
func ChannelsAPIHandler(s Service) http.HandlerFunc {
2019-01-14 20:07:11 +00:00
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response.Handler(w, response.HandlerFunc(func() (int, error) {
cc, err := s.Channels()
if err != nil {
return http.StatusBadRequest, err
}
return response.New(cc, r).Send(w, http.StatusOK)
}))
})
}