From ab1b709c77bf4654c1b05c8d705d83e82ee456be Mon Sep 17 00:00:00 2001 From: Elias Kohout Date: Fri, 27 Dec 2024 03:25:44 +0100 Subject: [PATCH] restructuring --- cmd/{ => crowsnest-frontend}/main.go | 7 ++++++- go.mod | 2 +- internal/data/datastore.go | 8 ++++++++ internal/model/article.go | 24 ++++++++++++++++++++++++ {static => web/static}/index.html | 0 5 files changed, 39 insertions(+), 2 deletions(-) rename cmd/{ => crowsnest-frontend}/main.go (76%) create mode 100644 internal/data/datastore.go create mode 100644 internal/model/article.go rename {static => web/static}/index.html (100%) diff --git a/cmd/main.go b/cmd/crowsnest-frontend/main.go similarity index 76% rename from cmd/main.go rename to cmd/crowsnest-frontend/main.go index d3e8eff..c252090 100644 --- a/cmd/main.go +++ b/cmd/crowsnest-frontend/main.go @@ -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) } diff --git a/go.mod b/go.mod index bf50988..8d93d36 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module frontend +module crowsnest-frontend go 1.23.3 diff --git a/internal/data/datastore.go b/internal/data/datastore.go new file mode 100644 index 0000000..1563067 --- /dev/null +++ b/internal/data/datastore.go @@ -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 +} diff --git a/internal/model/article.go b/internal/model/article.go new file mode 100644 index 0000000..d60e726 --- /dev/null +++ b/internal/model/article.go @@ -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[:]) +} diff --git a/static/index.html b/web/static/index.html similarity index 100% rename from static/index.html rename to web/static/index.html