Add basic index page.
This commit is contained in:
parent
677ac4f427
commit
cd4592d257
2 changed files with 85 additions and 8 deletions
39
main.go
39
main.go
|
@ -1,15 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"html/template"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func main() {
|
||||
e := echo.New()
|
||||
e.GET("/", func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "Hello, World!")
|
||||
})
|
||||
e.Logger.Fatal(e.Start(":1323"))
|
||||
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"))
|
||||
}
|
||||
|
||||
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", map[string]interface{}{
|
||||
"host": c.Request().Host,
|
||||
"upload_only": true,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue