私はgolangの初心者です。それを学ぶために、ginフレームワークを使用した単純な Web アプリから始めました。gin doc と構成済みのテンプレート ファイルに従いましたが、機能させることができません。エラーが発生しました -
panic: html/template: pattern matches no files: `templates/*` goroutine 1 [running]: html/template.Must /usr/local/Cellar/go/1.5.2/libexec/src/html/template/template.go:330 github.com/gin-gonic/gin.(*Engine).LoadHTMLGlob /Users/ameypatil/deployment/go/src/github.com/gin-gonic/gin/gin.go:126 main.main() /Users/ameypatil/deployment/go/src/github.com/ameykpatil/gospike/main.go:17
以下は私のコードです -
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
//os.Setenv("GIN_MODE", "release")
//gin.SetMode(gin.ReleaseMode)
// Creates a gin router with default middleware:
// logger and recovery (crash-free) middleware
router := gin.Default()
router.LoadHTMLGlob("templates/*")
//router.LoadHTMLFiles("templates/index.tmpl")
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "GoSpike",
})
})
// By default it serves on :8080 unless a
// PORT environment variable was defined.
router.Run(":4848")
}
私のディレクトリ構造は
- gospike
--- templates
------index.tmpl
--- main.go
go install
コマンドはエラーを出さない
しかし、実際に実行すると、上記のエラーが発生します。検索したところ、gin の github リポジトリに同様の問題が記録されていましたが、現在は閉鎖されています。私はさまざまなことを試しましたが、明らかな何かが欠けていると思います。私は何が欠けていますか?