Skip to content

Commit

Permalink
first rendered template
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarvardt committed Jul 19, 2014
1 parent 282e15e commit b245c52
Show file tree
Hide file tree
Showing 25 changed files with 10,315 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
*.o
*.a
*.so
main

# Folders
_obj
_test
.DS_Store

# Architecture specific extensions/prefixes
*.[568vq]
Expand All @@ -23,4 +25,3 @@ _testmain.go
*.test

.godeps
main
10 changes: 10 additions & 0 deletions controller/front.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package controller

import (
"github.com/gin-gonic/gin"
"github.com/flosch/pongo2"
)

func FrontController(c *gin.Context) {
pongo2Render(c, "./view/index.html", pongo2.Context{})
}
15 changes: 15 additions & 0 deletions controller/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package controller

import (
"github.com/gin-gonic/gin"
"github.com/flosch/pongo2"
)

func pongo2Render(c *gin.Context, templatePath string, ctx pongo2.Context) {
tpl, _ := pongo2.FromFile(templatePath)
out, _ := tpl.Execute(ctx)

c.Writer.Header().Set("Content-Type", "text/html")
c.Writer.WriteHeader(200)
c.Writer.Write([]byte(out))
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (
"github.com/gin-gonic/gin"

"./cfg"
"./controller"
)

func main() {
r := gin.Default()

r.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
r.GET("/", controller.FrontController)

r.Static("/static", "./static")

addr := cfg.String("addr")
cfg.Log(fmt.Sprintf("Running @ %s", addr))
Expand Down
Loading

0 comments on commit b245c52

Please sign in to comment.