Improve logging and handling of items
This commit is contained in:
parent
1a95c882ad
commit
7ed1d17373
|
@ -228,10 +228,9 @@ func (b *memoryBackend) feedItems(fetchURL, contentType string, body io.Reader)
|
||||||
//r["_id"] = "" // generate random value
|
//r["_id"] = "" // generate random value
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, e := r["published"]; e {
|
// mapToItem adds published
|
||||||
item := mapToItem(r)
|
item := mapToItem(r)
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if strings.HasPrefix(contentType, "application/json") { // json feed?
|
} else if strings.HasPrefix(contentType, "application/json") { // json feed?
|
||||||
var feed JSONFeed
|
var feed JSONFeed
|
||||||
|
@ -329,6 +328,14 @@ func (b *memoryBackend) feedItems(fetchURL, contentType string, body io.Reader)
|
||||||
items[i] = v
|
items[i] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, v := range items {
|
||||||
|
log.Printf("Id=%s Name=%s\n", item.Id, item.Name)
|
||||||
|
log.Printf("Author=%#v\n", item.Author)
|
||||||
|
log.Printf("Text=%s\n", item.Content.Text)
|
||||||
|
log.Printf("HTML=%s\n", item.Content.HTML)
|
||||||
|
}
|
||||||
|
|
||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,6 +389,9 @@ func (b *memoryBackend) channelAddItem(channel string, item microsub.Item) {
|
||||||
Data: data,
|
Data: data,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("Adding item to channel %s\n", channel)
|
||||||
|
log.Printf("%#v\n", forRedis)
|
||||||
|
|
||||||
itemKey := fmt.Sprintf("item:%s", item.ID)
|
itemKey := fmt.Sprintf("item:%s", item.ID)
|
||||||
_, err = redis.String(conn.Do("HMSET", redis.Args{}.Add(itemKey).AddFlat(&forRedis)...))
|
_, err = redis.String(conn.Do("HMSET", redis.Args{}.Add(itemKey).AddFlat(&forRedis)...))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -346,6 +346,8 @@ func mapToItem(result map[string]interface{}) microsub.Item {
|
||||||
|
|
||||||
if published, e := result["published"]; e {
|
if published, e := result["published"]; e {
|
||||||
item.Published = published.(string)
|
item.Published = published.(string)
|
||||||
|
} else {
|
||||||
|
item.Published = time.Now().Format(time.RFC3339)
|
||||||
}
|
}
|
||||||
|
|
||||||
if updated, e := result["updated"]; e {
|
if updated, e := result["updated"]; e {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user