Skip to content
This repository was archived by the owner on Sep 23, 2021. It is now read-only.

Commit 4e0b63b

Browse files
committed
Changed session logic
1 parent e72437e commit 4e0b63b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

main.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
haikunator "github.com/atrox/haikunatorgo"
1414
"github.com/gin-contrib/sessions"
1515
"github.com/gin-gonic/gin"
16+
"github.com/msoedov/hacker-slides/files"
1617
)
1718

1819
const sessionHeader = "slide-session"
@@ -75,15 +76,23 @@ func NewApp() *gin.Engine {
7576

7677
r.GET("/", func(c *gin.Context) {
7778

78-
fname := c.Param("name")
79+
latest := files.LatestFileIn("slides")
7980
log.WithFields(log.Fields{
80-
"name": fname,
81-
}).Info("Restore?")
81+
"name": latest,
82+
}).Info("Restoring latest point")
83+
84+
var path string
85+
if latest == "" {
86+
haikunator := haikunator.New()
87+
haikunator.TokenLength = 0
88+
name := haikunator.Haikunate()
89+
path = fmt.Sprintf("slides/%s.md", name)
90+
} else {
91+
name := latest
92+
path = fmt.Sprintf("slides/%s", name)
93+
94+
}
8295

83-
haikunator := haikunator.New()
84-
haikunator.TokenLength = 0
85-
name := haikunator.Haikunate()
86-
path := fmt.Sprintf("slides/%s.md", name)
8796
log.WithFields(log.Fields{
8897
"path": path,
8998
}).Info("A new session")

0 commit comments

Comments
 (0)