subscription.go 942 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package api
  5. import (
  6. "errors"
  7. "fmt"
  8. "net/http"
  9. "github.com/miniflux/miniflux/http/response/json"
  10. "github.com/miniflux/miniflux/reader/subscription"
  11. )
  12. // GetSubscriptions is the API handler to find subscriptions.
  13. func (c *Controller) GetSubscriptions(w http.ResponseWriter, r *http.Request) {
  14. subscriptionInfo, err := decodeURLPayload(r.Body)
  15. if err != nil {
  16. json.BadRequest(w, err)
  17. return
  18. }
  19. subscriptions, err := subscription.FindSubscriptions(
  20. subscriptionInfo.URL,
  21. subscriptionInfo.Username,
  22. subscriptionInfo.Password,
  23. )
  24. if err != nil {
  25. json.ServerError(w, errors.New("Unable to discover subscriptions"))
  26. return
  27. }
  28. if subscriptions == nil {
  29. json.NotFound(w, fmt.Errorf("No subscription found"))
  30. return
  31. }
  32. json.OK(w, r, subscriptions)
  33. }