dataEconomy/main.go

46 lines
769 B
Go
Raw Normal View History

2016-02-29 20:16:20 +01:00
package main
import (
"github.com/gin-gonic/gin"
"io/ioutil"
)
var DB = make(map[string]string)
func NewApp() *gin.Engine {
r := gin.Default()
2016-02-29 20:42:00 +01:00
r.LoadHTMLGlob("templates/index.tmpl")
r.Static("/static", "./static")
2016-02-29 20:29:47 +01:00
r.GET("/", func(c *gin.Context) {
2016-02-29 20:42:00 +01:00
c.HTML(200, "users/index.tmpl", gin.H{
2016-02-29 20:29:47 +01:00
"pubTo": "Users",
})
})
2016-02-29 20:16:20 +01:00
r.GET("/slides.md", func(c *gin.Context) {
body, err := ioutil.ReadFile("initial-slides.md")
if err != nil {
panic(err)
}
2016-02-29 21:01:13 +01:00
ioutil.WriteFile("slides.md", body, 0644)
2016-02-29 20:16:20 +01:00
c.String(200, string(body))
})
2016-02-29 20:29:47 +01:00
r.PUT("/slides.md", func(c *gin.Context) {
2016-02-29 21:01:13 +01:00
body, _ := ioutil.ReadAll(c.Request.Body);
ioutil.WriteFile("slides.md", body, 0644)
c.String(200, "")
2016-02-29 20:16:20 +01:00
})
return r
}
func main() {
r := NewApp()
r.Run(":8080")
}