Created
December 28, 2017 06:34
-
-
Save altn980/f2ff9186fe6a091d89beb5b780f1d04c to your computer and use it in GitHub Desktop.
Golang - Echo - 簡易サンプル
This file contains 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 ( | |
"html/template" | |
"io" | |
"net/http" | |
"github.com/labstack/echo" | |
) | |
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 Index(c echo.Context) error { | |
return c.Render(http.StatusOK, "index", "World") | |
} | |
func main() { | |
t := &Template{ | |
templates: template.Must(template.ParseGlob("public/views/*.html")), | |
} | |
e := echo.New() | |
e.Renderer = t | |
e.GET("/", Index) | |
e.Logger.Fatal(e.Start(":1323")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment