###問題
現在Go言語でフレームワークのechoを試しています。
テンプレートの適用を試しているのですが、
http://localhost:8080/にアクセスしてもInternal Server Errorと表示されます。
エラーは以下の物が返ってきます。
echoのドキュメントのサンプル通りに作っているはずなのですが何がいけないのでしょうか。
###エラーメッセージ
html/template: "index" is undefined
###ソースコード
main.goとtemplateフォルダは同じ階層にあります。
main.go ------ package main import ( "html/template" "io" "log" "net/http" "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 rootHandler(c echo.Context) error { err := c.Render(http.StatusOK, "index", "") log.Println(err) return err } func main() { t := &Template{ templates: template.Must(template.ParseGlob("template/*.html")), } e := echo.New() e.SetRenderer(t) e.GET("/", rootHandler) e.Run(standard.New(":8080")) }
template/index.html ------ <html> <head> <title>TOP</title> </head> <body> <h2>トップページ</h2> <p><a href="/login">ログイン</a></p> </body> </html>
###環境
Go: go version go1.7.1 windows/386
echo: v2
OS: Windows 10 pro
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/21 08:27