Move all structs to model.go

This commit is contained in:
Joakim Hellsén 2024-02-04 17:09:52 +01:00
commit a7630d7443
2 changed files with 27 additions and 26 deletions

30
main.go
View file

@ -59,30 +59,8 @@ func main() {
http.ListenAndServe("127.0.0.1:8000", r) http.ListenAndServe("127.0.0.1:8000", r)
} }
type Data struct {
Title string
Description string
Keywords string
Author string
CanonicalURL string
FeedCount int
DatabaseSize string
Request *http.Request
ParseErrors []ParseResult
}
type ParseResult struct {
FeedURL string
Msg string
IsError bool
}
func (d *Data) GetDatabaseSizeAndFeedCount() {
d.DatabaseSize = GetDBSize()
}
func renderPage(w http.ResponseWriter, title, description, keywords, author, url, templateName string) { func renderPage(w http.ResponseWriter, title, description, keywords, author, url, templateName string) {
data := Data{ data := TemplateData{
Title: title, Title: title,
Description: description, Description: description,
Keywords: keywords, Keywords: keywords,
@ -101,7 +79,7 @@ func renderPage(w http.ResponseWriter, title, description, keywords, author, url
} }
func NotFoundHandler(w http.ResponseWriter, r *http.Request) { func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
data := Data{ data := TemplateData{
Request: r, Request: r,
} }
data.GetDatabaseSizeAndFeedCount() data.GetDatabaseSizeAndFeedCount()
@ -115,7 +93,7 @@ func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
} }
func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request) { func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request) {
data := Data{ data := TemplateData{
Request: r, Request: r,
} }
data.GetDatabaseSizeAndFeedCount() data.GetDatabaseSizeAndFeedCount()
@ -222,7 +200,7 @@ func AddFeedHandler(w http.ResponseWriter, r *http.Request) {
} }
// Render the index page with the parse errors // Render the index page with the parse errors
data := Data{ data := TemplateData{
Title: "FeedVault", Title: "FeedVault",
Description: "FeedVault - A feed archive", Description: "FeedVault - A feed archive",
Keywords: "RSS, Atom, Feed, Archive", Keywords: "RSS, Atom, Feed, Archive",

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"net/http"
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
@ -155,3 +156,25 @@ type Extension struct {
Attrs map[string]string `gorm:"type:json" json:"attrs"` Attrs map[string]string `gorm:"type:json" json:"attrs"`
Children map[string][]Extension `gorm:"type:json" json:"children"` Children map[string][]Extension `gorm:"type:json" json:"children"`
} }
type TemplateData struct {
Title string
Description string
Keywords string
Author string
CanonicalURL string
FeedCount int
DatabaseSize string
Request *http.Request
ParseErrors []ParseResult
}
type ParseResult struct {
FeedURL string
Msg string
IsError bool
}
func (d *TemplateData) GetDatabaseSizeAndFeedCount() {
d.DatabaseSize = GetDBSize()
}