Add Path function

This commit is contained in:
Alex Myasoedov 2018-01-18 20:18:50 -05:00
parent d844211d22
commit 0a5d7931e4
No known key found for this signature in database
GPG key ID: D261413C245982F0

10
main.go
View file

@ -63,6 +63,10 @@ func authorizationHeader(user, password string) string {
return "Basic " + base64.StdEncoding.EncodeToString([]byte(base)) return "Basic " + base64.StdEncoding.EncodeToString([]byte(base))
} }
func SlidePath(name string) string {
return fmt.Sprintf("slides/%s.md", name)
}
func NewApp() *gin.Engine { func NewApp() *gin.Engine {
r := gin.Default() r := gin.Default()
@ -90,7 +94,7 @@ func NewApp() *gin.Engine {
} else { } else {
name = strings.Replace(latest, ".md", "", 1) name = strings.Replace(latest, ".md", "", 1)
} }
path = fmt.Sprintf("slides/%s.md", name) path = SlidePath(name)
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"path": path, "path": path,
@ -185,7 +189,7 @@ func NewApp() *gin.Engine {
if strings.HasSuffix(name, ".md") { if strings.HasSuffix(name, ".md") {
name = name[0 : len(name)-3] name = name[0 : len(name)-3]
} }
path := fmt.Sprintf("slides/%s.md", name) path := SlidePath(name)
session := sessions.Default(c) session := sessions.Default(c)
session.Set("name", path) session.Set("name", path)
session.Save() session.Save()
@ -205,7 +209,7 @@ func NewApp() *gin.Engine {
if strings.HasSuffix(name, ".md") { if strings.HasSuffix(name, ".md") {
name = name[0 : len(name)-3] name = name[0 : len(name)-3]
} }
path := fmt.Sprintf("slides/%s.md", name) path := SlidePath(name)
session := sessions.Default(c) session := sessions.Default(c)
session.Set("name", path) session.Set("name", path)
session.Save() session.Save()