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")) | |
} |
{{define "hello"}} | |
Hello,{{.}} | |
{{end}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment