Created
August 18, 2016 03:37
-
-
Save tkc/e6a3d8b5f82c8eae76db7b283d23838a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "io" | |
| "fmt" | |
| "net/http" | |
| "html/template" | |
| "github.com/labstack/echo" | |
| "github.com/labstack/echo/engine/standard" | |
| ) | |
| type Template struct { | |
| templates *template.Template | |
| } | |
| func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error { | |
| return t.templates.ExecuteTemplate(w, name, data) | |
| } | |
| func Hello(c echo.Context) error { | |
| return c.Render(http.StatusOK, "hello", "world") | |
| } | |
| func main() { | |
| fmt.Println("sever start") | |
| t := &Template{ | |
| templates: template.Must(template.ParseGlob("public/views/*.html")), | |
| } | |
| e := echo.New() | |
| e.SetRenderer(t) | |
| e.GET("/hello", Hello) | |
| e.Run(standard.New(":3001")) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {{define "hello"}} | |
| Hello,{{.}} | |
| {{end}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment