add viewmodel for article
This commit is contained in:
33
internal/model/Article.go
Normal file
33
internal/model/Article.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
// TODO docstring
|
||||
type Article struct {
|
||||
SourceUrl string
|
||||
PublishDate time.Time
|
||||
FetchDate time.Time
|
||||
Title string
|
||||
Content string
|
||||
Author 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[:])
|
||||
}
|
||||
|
||||
|
||||
// --- implement IIdentifiable interface ---
|
||||
|
||||
// Using the Identifier attribute as the Id.
|
||||
func (article *Article) Id() string {
|
||||
return article.Hash()
|
||||
}
|
||||
Reference in New Issue
Block a user