1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

Use vanilla HTTP handlers (refactoring)

This commit is contained in:
Frédéric Guillot 2018-04-29 16:35:04 -07:00
parent 1eba1730d1
commit f49b42f70f
121 changed files with 4339 additions and 3369 deletions

View file

@ -7,29 +7,30 @@ package api
import (
"errors"
"fmt"
"net/http"
"github.com/miniflux/miniflux/http/handler"
"github.com/miniflux/miniflux/http/response/json"
"github.com/miniflux/miniflux/reader/subscription"
)
// GetSubscriptions is the API handler to find subscriptions.
func (c *Controller) GetSubscriptions(ctx *handler.Context, request *handler.Request, response *handler.Response) {
websiteURL, err := decodeURLPayload(request.Body())
func (c *Controller) GetSubscriptions(w http.ResponseWriter, r *http.Request) {
websiteURL, err := decodeURLPayload(r.Body)
if err != nil {
response.JSON().BadRequest(err)
json.BadRequest(w, err)
return
}
subscriptions, err := subscription.FindSubscriptions(websiteURL)
if err != nil {
response.JSON().ServerError(errors.New("Unable to discover subscriptions"))
json.ServerError(w, errors.New("Unable to discover subscriptions"))
return
}
if subscriptions == nil {
response.JSON().NotFound(fmt.Errorf("No subscription found"))
json.NotFound(w, fmt.Errorf("No subscription found"))
return
}
response.JSON().Standard(subscriptions)
json.OK(w, subscriptions)
}