restructuring

This commit is contained in:
2024-12-27 03:25:44 +01:00
parent a711e5742d
commit ab1b709c77
5 changed files with 39 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"net/http"
"crowsnest-frontend/internal/model"
)
func test(w http.ResponseWriter, req *http.Request) {
@@ -21,5 +22,9 @@ func main() {
http.Handle("/", http.StripPrefix("/", fs))
http.ListenAndServe(":8090", nil)
a := &model.Article{}
fmt.Println(a.Hash())
//http.ListenAndServe(":8090", nil)
}

2
go.mod
View File

@@ -1,3 +1,3 @@
module frontend
module crowsnest-frontend
go 1.23.3

View File

@@ -0,0 +1,8 @@
package data
type Datastore interface {
Set(key string) error
Get(key string) string, error
GetAll(rowkey string) map[string]string, error
GetAllKeys() map[string]bool, error
}

24
internal/model/article.go Normal file
View File

@@ -0,0 +1,24 @@
package model
import (
"time"
"crypto/sha256"
"encoding/hex"
)
type Article struct {
SourceUrl string
PublishDate time.Time
FetchDate time.Time
Title string
Content string
}
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[:])
}