Files
crowsnest/internal/model/article.go

33 lines
619 B
Go
Raw Normal View History

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