restructuring
This commit is contained in:
@@ -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)
|
||||
}
|
||||
8
internal/data/datastore.go
Normal file
8
internal/data/datastore.go
Normal 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
24
internal/model/article.go
Normal 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[:])
|
||||
}
|
||||
Reference in New Issue
Block a user