Skip to content

Instantly share code, notes, and snippets.

@altn980
Created December 28, 2017 06:34
Show Gist options
  • Save altn980/f2ff9186fe6a091d89beb5b780f1d04c to your computer and use it in GitHub Desktop.
Save altn980/f2ff9186fe6a091d89beb5b780f1d04c to your computer and use it in GitHub Desktop.
Golang - Echo - 簡易サンプル
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