From 4e0b63b38ba0e356c7eba9bfbaad70319a3b1142 Mon Sep 17 00:00:00 2001 From: Alex Myasoedov Date: Thu, 18 Jan 2018 20:01:16 -0500 Subject: [PATCH] Changed session logic --- main.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 39707ac..1ff7682 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( haikunator "github.com/atrox/haikunatorgo" "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" + "github.com/msoedov/hacker-slides/files" ) const sessionHeader = "slide-session" @@ -75,15 +76,23 @@ func NewApp() *gin.Engine { r.GET("/", func(c *gin.Context) { - fname := c.Param("name") + latest := files.LatestFileIn("slides") log.WithFields(log.Fields{ - "name": fname, - }).Info("Restore?") + "name": latest, + }).Info("Restoring latest point") + + var path string + if latest == "" { + haikunator := haikunator.New() + haikunator.TokenLength = 0 + name := haikunator.Haikunate() + path = fmt.Sprintf("slides/%s.md", name) + } else { + name := latest + path = fmt.Sprintf("slides/%s", name) + + } - haikunator := haikunator.New() - haikunator.TokenLength = 0 - name := haikunator.Haikunate() - path := fmt.Sprintf("slides/%s.md", name) log.WithFields(log.Fields{ "path": path, }).Info("A new session")