From 268fcf7e6b671d4959a12111d5abf553bf0a201b Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sun, 24 Oct 2021 12:52:38 -0400 Subject: Redis caching. Linter config and cleanup. --- page/time.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'page/time.go') diff --git a/page/time.go b/page/time.go index 0374490..cd419c8 100644 --- a/page/time.go +++ b/page/time.go @@ -1,10 +1,14 @@ package page import ( - "gopkg.in/yaml.v3" + "fmt" "time" + + "gopkg.in/yaml.v3" ) +// PageTime allows us to slip in a different time format for loading/unloading +// the yaml from disk than the default. type PageTime struct { time.Time } @@ -13,16 +17,22 @@ type PageTime struct { // from the yaml information. var TimeFormat = "01.02.2006 15:04:05 MST" +// UnmarshalYAML override the default and parse our time with the global time +// format. func (pt *PageTime) UnmarshalYAML(n *yaml.Node) error { t, err := time.Parse(TimeFormat, n.Value) if err != nil { - return err + return fmt.Errorf("pagetime: %w", err) } + pt.Time = t + return nil } +// MarshalYAML override the default with our own time format. func (pt PageTime) MarshalYAML() (interface{}, error) { s := pt.Time.Format(TimeFormat) + return s, nil } -- cgit v1.2.3