Files
crowsnest/internal/model/article.go

34 lines
658 B
Go
Raw Normal View History

2024-12-27 03:25:44 +01:00
package model
import (
"time"
"crypto/sha256"
"encoding/hex"
)
2024-12-28 01:40:30 +01:00
// TODO docstring
2024-12-27 03:25:44 +01:00
type Article struct {
2024-12-27 22:34:43 +01:00
SourceUrl string
PublishDate time.Time
FetchDate time.Time
Title string
Content string
Author string
2024-12-27 03:25:44 +01:00
}
2024-12-27 22:34:43 +01:00
2024-12-28 01:40:30 +01:00
// Generates a hash based on the source url of the article. Can be used to
// identify the article.
2024-12-27 03:25:44 +01:00
func (article *Article) Hash() string {
hash := sha256.Sum256([]byte(article.SourceUrl))
return hex.EncodeToString(hash[:])
}
2024-12-27 22:34:43 +01:00
2024-12-28 01:40:30 +01:00
// --- implement IIdentifiable interface ---
2024-12-27 22:34:43 +01:00
2024-12-28 01:40:30 +01:00
// Using the Identifier attribute as the Id.
func (article *Article) Id() string {
return article.Hash()
2024-12-27 22:34:43 +01:00
}