From cd7f01f573def1939ba0bc2bd1ee2d3094d01eb1 Mon Sep 17 00:00:00 2001 From: jtagcat Date: Mon, 3 Oct 2022 17:23:12 +0300 Subject: [PATCH] client.New(): accept endpoint URLs with /v1/ --- client/client.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/client.go b/client/client.go index 1f4d11a8..218e7899 100644 --- a/client/client.go +++ b/client/client.go @@ -10,6 +10,7 @@ import ( "io" "net/url" "strconv" + "strings" ) // Client holds API procedure calls. @@ -19,6 +20,11 @@ type Client struct { // New returns a new Miniflux client. func New(endpoint string, credentials ...string) *Client { + // Web gives "API Endpoint = https://miniflux.app/v1/", it doesn't work (/v1/v1/me) + endpoint = strings.TrimSuffix(endpoint, "/") + endpoint = strings.TrimSuffix(endpoint, "/v1") + // trim to https://miniflux.app + if len(credentials) == 2 { return &Client{request: &request{endpoint: endpoint, username: credentials[0], password: credentials[1]}} } @@ -181,7 +187,6 @@ func (c *Client) CreateCategory(title string) (*Category, error) { body, err := c.request.Post("/v1/categories", map[string]interface{}{ "title": title, }) - if err != nil { return nil, err } @@ -201,7 +206,6 @@ func (c *Client) UpdateCategory(categoryID int64, title string) (*Category, erro body, err := c.request.Put(fmt.Sprintf("/v1/categories/%d", categoryID), map[string]interface{}{ "title": title, }) - if err != nil { return nil, err }