From a7630d74435d1694af578c6f962172c30d7f0da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Sun, 4 Feb 2024 17:09:52 +0100 Subject: [PATCH] Move all structs to model.go --- main.go | 30 ++++-------------------------- models.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/main.go b/main.go index c196811..3d80a07 100644 --- a/main.go +++ b/main.go @@ -59,30 +59,8 @@ func main() { 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) { - data := Data{ + data := TemplateData{ Title: title, Description: description, Keywords: keywords, @@ -101,7 +79,7 @@ func renderPage(w http.ResponseWriter, title, description, keywords, author, url } func NotFoundHandler(w http.ResponseWriter, r *http.Request) { - data := Data{ + data := TemplateData{ Request: r, } data.GetDatabaseSizeAndFeedCount() @@ -115,7 +93,7 @@ func NotFoundHandler(w http.ResponseWriter, r *http.Request) { } func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request) { - data := Data{ + data := TemplateData{ Request: r, } data.GetDatabaseSizeAndFeedCount() @@ -222,7 +200,7 @@ func AddFeedHandler(w http.ResponseWriter, r *http.Request) { } // Render the index page with the parse errors - data := Data{ + data := TemplateData{ Title: "FeedVault", Description: "FeedVault - A feed archive", Keywords: "RSS, Atom, Feed, Archive", diff --git a/models.go b/models.go index ec19b77..dc1db16 100644 --- a/models.go +++ b/models.go @@ -1,6 +1,7 @@ package main import ( + "net/http" "time" "gorm.io/gorm" @@ -155,3 +156,25 @@ type Extension struct { Attrs map[string]string `gorm:"type:json" json:"attrs"` 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() +}