나는 골란에 초보자입니다. 나는 그것을 배우기 위해서 gin 프레임 워크를 사용하는 간단한 웹 앱으로 시작했다. 나는 진 진보적 인 문서 & 템플릿 파일을 따라 갔지만 제대로 작동하지는 못했습니다. 나는이 오류가 무엇입니까 - 아래진 프레임 워크에서 템플릿을 작동시키는 방법은 무엇입니까?
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 repo에 기록 된 비슷한 문제가 있었지만 지금은 닫았습니다. 여러 가지 시도를했지만 분명히 뭔가 빠져있는 것 같습니다. 내가 뭘 놓치고 있니?
완벽하게 일했다! – ameykpatil