restructuring
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
|
||||
// TODO docstring
|
||||
type Article struct {
|
||||
SourceUrl string
|
||||
@@ -16,18 +17,38 @@ type Article struct {
|
||||
Author string
|
||||
}
|
||||
|
||||
// TODO docstring
|
||||
type ArticleViewModel struct {
|
||||
Title string
|
||||
Author string
|
||||
PublishDate string
|
||||
SourceUrl string
|
||||
Summary string
|
||||
}
|
||||
|
||||
// Generates a hash based on the source url of the article. Can be used to
|
||||
// identify the article.
|
||||
func (article *Article) Hash() string {
|
||||
hash := sha256.Sum256([]byte(article.SourceUrl))
|
||||
return hex.EncodeToString(hash[:])
|
||||
|
||||
// TODO docstring
|
||||
func (a *Article) ViewModel() *ArticleViewModel {
|
||||
summary := a.Content
|
||||
if len(a.Content) > 300 {
|
||||
summary = summary[:300]
|
||||
}
|
||||
|
||||
return &ArticleViewModel{
|
||||
Title: a.Title,
|
||||
Author: a.Author,
|
||||
PublishDate: a.PublishDate.Local().Format("02.01.2006 03:04"),
|
||||
SourceUrl: a.SourceUrl,
|
||||
Summary: summary,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --- implement IIdentifiable interface ---
|
||||
|
||||
// Using the Identifier attribute as the Id.
|
||||
// Generates a hash based on the source url of the article. Can be used to
|
||||
// identify the article.
|
||||
func (article *Article) Id() string {
|
||||
return article.Hash()
|
||||
hash := sha256.Sum256([]byte(article.SourceUrl))
|
||||
return hex.EncodeToString(hash[:])
|
||||
}
|
||||
Reference in New Issue
Block a user