Compare commits

..

No commits in common. "17bee2852adb20553cfc4b9c8647eec5497bd3db" and "e6201eacef03df937d06ad20be0a328043a4253e" have entirely different histories.

3 changed files with 6 additions and 49 deletions

View File

@ -127,13 +127,6 @@ func (c *Client) ChannelsGetList() ([]microsub.Channel, error) {
return []microsub.Channel{}, err return []microsub.Channel{}, err
} }
defer res.Body.Close() defer res.Body.Close()
if res.StatusCode != 200 {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return []microsub.Channel{}, fmt.Errorf("HTTP Status is not 200, but %d, error while reading body", res.StatusCode)
}
return []microsub.Channel{}, fmt.Errorf("HTTP Status is not 200, but %d: %s", res.StatusCode, body)
}
type channelsResponse struct { type channelsResponse struct {
Channels []microsub.Channel `json:"channels"` Channels []microsub.Channel `json:"channels"`
@ -156,13 +149,6 @@ func (c *Client) TimelineGet(before, after, channel string) (microsub.Timeline,
return microsub.Timeline{}, err return microsub.Timeline{}, err
} }
defer res.Body.Close() defer res.Body.Close()
if res.StatusCode != 200 {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return microsub.Timeline{}, fmt.Errorf("HTTP Status is not 200, but %d, error while reading body", res.StatusCode)
}
return microsub.Timeline{}, fmt.Errorf("HTTP Status is not 200, but %d: %s", res.StatusCode, body)
}
dec := json.NewDecoder(res.Body) dec := json.NewDecoder(res.Body)
var timeline microsub.Timeline var timeline microsub.Timeline
err = dec.Decode(&timeline) err = dec.Decode(&timeline)
@ -180,16 +166,8 @@ func (c *Client) PreviewURL(url string) (microsub.Timeline, error) {
return microsub.Timeline{}, err return microsub.Timeline{}, err
} }
defer res.Body.Close() defer res.Body.Close()
var timeline microsub.Timeline
if res.StatusCode != 200 {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return timeline, fmt.Errorf("HTTP Status is not 200, but %d, error while reading body", res.StatusCode)
}
return timeline, fmt.Errorf("HTTP Status is not 200, but %d: %s", res.StatusCode, body)
}
dec := json.NewDecoder(res.Body) dec := json.NewDecoder(res.Body)
var timeline microsub.Timeline
err = dec.Decode(&timeline) err = dec.Decode(&timeline)
if err != nil { if err != nil {
return microsub.Timeline{}, err return microsub.Timeline{}, err
@ -205,13 +183,6 @@ func (c *Client) FollowGetList(channel string) ([]microsub.Feed, error) {
return []microsub.Feed{}, nil return []microsub.Feed{}, nil
} }
defer res.Body.Close() defer res.Body.Close()
if res.StatusCode != 200 {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return []microsub.Feed{}, fmt.Errorf("HTTP Status is not 200, but %d, error while reading body", res.StatusCode)
}
return []microsub.Feed{}, fmt.Errorf("HTTP Status is not 200, but %d: %s", res.StatusCode, body)
}
dec := json.NewDecoder(res.Body) dec := json.NewDecoder(res.Body)
type followResponse struct { type followResponse struct {
Items []microsub.Feed `json:"items"` Items []microsub.Feed `json:"items"`

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net" "net"
"net/http" "net/http"
@ -41,14 +40,6 @@ func GetEndpoints(me *url.URL) (Endpoints, error) {
} }
defer res.Body.Close() defer res.Body.Close()
if res.StatusCode != 200 {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return endpoints, fmt.Errorf("error from endpoint while reading body %d", res.StatusCode)
}
return endpoints, fmt.Errorf("error from endpoint %d: %s", res.StatusCode, body)
}
var links linkheader.Links var links linkheader.Links
if headers, e := res.Header["Link"]; e { if headers, e := res.Header["Link"]; e {

View File

@ -169,21 +169,16 @@ func simplify(itemType string, item map[string][]interface{}, author map[string]
return feedItem return feedItem
} }
func simplifyCard(v []interface{}) (map[string]string, error) { func simplifyCard(v []interface{}) (map[string]string, error) {
card := make(map[string]string)
card["type"] = "card"
if value, ok := v[0].(*microformats.Microformat); ok { if value, ok := v[0].(*microformats.Microformat); ok {
card := make(map[string]string)
card["type"] = "card"
for ik, vk := range value.Properties { for ik, vk := range value.Properties {
if p, ok := vk[0].(string); ok { if p, ok := vk[0].(string); ok {
card[ik] = p card[ik] = p
} }
} }
return card, nil return card, nil
} else if value, ok := v[0].(string); ok {
card["url"] = value
return card, nil
} }
return nil, fmt.Errorf("not convertable to a card %q", v) return nil, fmt.Errorf("not convertable to a card %q", v)
} }
@ -231,9 +226,9 @@ func SimplifyMicroformatData(md *microformats.Data) []map[string]interface{} {
newItem := SimplifyMicroformat(item, nil) newItem := SimplifyMicroformat(item, nil)
delete(newItem, "children") delete(newItem, "children")
if newItem["type"] == "entry" || newItem["type"] == "event" || newItem["type"] == "card" { // if newItem["type"] == "entry" || newItem["type"] == "event" || newItem["type"] == "card" {
items = append(items, newItem) // items = append(items, newItem)
} // }
// if c, e := newItem["children"]; e { // if c, e := newItem["children"]; e {
// if ar, ok := c.([]map[string]interface{}); ok { // if ar, ok := c.([]map[string]interface{}); ok {
// for _, item := range ar { // for _, item := range ar {