From 20d1b189cae9302a563607c22ad7f4010d6a390d Mon Sep 17 00:00:00 2001 From: Alex Myasoedov Date: Mon, 29 Feb 2016 22:34:47 +0200 Subject: [PATCH] Cleaned up --- .gitignore | 1 + main.go | 10 +++++++--- templates/index.tmpl | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 2bdf995..ebb631c 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ _testmain.go *.exe bin/ src/ +slides/ diff --git a/main.go b/main.go index 404f50c..bbf9698 100644 --- a/main.go +++ b/main.go @@ -23,10 +23,11 @@ func NewApp() *gin.Engine { haikunator := haikunator.NewHaikunator() haikunator.TokenLength = 0 name := haikunator.Haikunate() - path := fmt.Sprintf("%s.md", name) + path := fmt.Sprintf("slides/%s.md", name) session := sessions.Default(c) session.Set("name", path) session.Save() + c.HTML(200, "users/index.tmpl", gin.H{ "pubTo": path, }) @@ -37,14 +38,17 @@ func NewApp() *gin.Engine { val := session.Get("name") path, ok := val.(string) if !ok { - panic("unlucky") + c.String(400, "No context") } if _, err := os.Stat(path); err != nil { + // coppy sapmle markdown file to the path body, err := ioutil.ReadFile("initial-slides.md") if err != nil { panic(err) } ioutil.WriteFile(path, body, 0644) + c.String(200, string(body)) + return } body, err := ioutil.ReadFile(path) @@ -59,7 +63,7 @@ func NewApp() *gin.Engine { val := session.Get("name") path, ok := val.(string) if !ok { - panic("unlucky") + c.String(400, "No context") } body, _ := ioutil.ReadAll(c.Request.Body) ioutil.WriteFile(path, body, 0644) diff --git a/templates/index.tmpl b/templates/index.tmpl index d07e382..f3dd8a4 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -14,7 +14,7 @@