diff options
author | Frédéric Guillot <fred@miniflux.net> | 2017-11-19 21:10:04 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2017-11-19 22:01:46 -0800 |
commit | 8ffb773f43c8dc54801ca1d111854e7e881c93c9 (patch) | |
tree | 38133a2fc612597a75fed1d13e5b4042f58a2b7e /model/feed.go |
First commit
Diffstat (limited to 'model/feed.go')
-rw-r--r-- | model/feed.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/model/feed.go b/model/feed.go new file mode 100644 index 0000000..17a9b25 --- /dev/null +++ b/model/feed.go @@ -0,0 +1,66 @@ +// Copyright 2017 Frédéric Guillot. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package model + +import ( + "fmt" + "reflect" + "time" +) + +// Feed represents a feed in the database +type Feed struct { + ID int64 `json:"id"` + UserID int64 `json:"user_id"` + FeedURL string `json:"feed_url"` + SiteURL string `json:"site_url"` + Title string `json:"title"` + CheckedAt time.Time `json:"checked_at,omitempty"` + EtagHeader string `json:"etag_header,omitempty"` + LastModifiedHeader string `json:"last_modified_header,omitempty"` + ParsingErrorMsg string `json:"parsing_error_message,omitempty"` + ParsingErrorCount int `json:"parsing_error_count,omitempty"` + Category *Category `json:"category,omitempty"` + Entries Entries `json:"entries,omitempty"` + Icon *FeedIcon `json:"icon,omitempty"` +} + +func (f *Feed) String() string { + return fmt.Sprintf("ID=%d, UserID=%d, FeedURL=%s, SiteURL=%s, Title=%s, Category={%s}", + f.ID, + f.UserID, + f.FeedURL, + f.SiteURL, + f.Title, + f.Category, + ) +} + +// Merge combine src to the current struct +func (f *Feed) Merge(src *Feed) { + src.ID = f.ID + src.UserID = f.UserID + + new := reflect.ValueOf(src).Elem() + for i := 0; i < new.NumField(); i++ { + field := new.Field(i) + + switch field.Interface().(type) { + case int64: + value := field.Int() + if value != 0 { + reflect.ValueOf(f).Elem().Field(i).SetInt(value) + } + case string: + value := field.String() + if value != "" { + reflect.ValueOf(f).Elem().Field(i).SetString(value) + } + } + } +} + +// Feeds is a list of feed +type Feeds []*Feed |