Giter Club home page Giter Club logo

Comments (5)

qloog avatar qloog commented on August 22, 2024

模板文件都在这个目录下: internal/templates, 本地测试正常。可以贴下你的访问方式。

from eagle.

957651480 avatar 957651480 commented on August 22, 2024

当我访问一个不存在的路由时就重现错误了
http://localhost:8080/err 请求路由不存在的路由报如下错误

2020/12/17 22:38:00 [Recovery] 2020/12/17 - 22:38:00 panic recovered:
GET /favicon.ico HTTP/1.1
Host: localhost:8080
Accept: image/webp,image/apng,image/,/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
Cookie: Phpstorm-963730c5=13220b42-a332-4f23-aec1-76fdf6d9933b; Hm_lvt_1d2d61263f13e4b288c8da19ad3ff56d=1601001166; Webstorm-8c079569=8575b6b7-f224-4821-9825-bc23dbb7b7bd
Referer: http://localhost:8080/
Sec-Fetch-Dest: image
Sec-Fetch-Mode: no-cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36

TemplateEngine render read name:error/404, path:D:\goworkspace\src\snake\internal\templates\error\404.html, error: open D:\goworkspace\src\snake\internal\templates\error\404.html: The system cannot find the path specified.
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:842 (0xe1c124)
(*Context).Render: panic(err)
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:851 (0xe1c1e4)
(*Context).HTML: c.Render(code, instance)
D:/goworkspace/src/snake/app/web/error.go:11 (0x1189664)
Error404: c.HTML(http.StatusOK, "error/404", gin.H{
D:/goworkspace/src/snake/router/web.go:24 (0x1189665)
LoadWebRouter.func1: web.Error404(c)
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xe18061)
(*Context).Next: c.handlersc.index
D:/goworkspace/src/snake/router/middleware/requestid.go:28 (0x117b74c)
RequestID.func1: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xe18061)
(*Context).Next: c.handlersc.index
D:/goworkspace/src/snake/router/middleware/header.go:24 (0x117a4e4)
Options: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xe18061)
(*Context).Next: c.handlersc.index
D:/goworkspace/src/snake/router/middleware/header.go:16 (0x117a476)
NoCache: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xe18061)
(*Context).Next: c.handlersc.index
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:83 (0xe2c726)
RecoveryWithWriter.func1: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xe18061)
(*Context).Next: c.handlersc.index
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0xe2b813)
LoggerWithConfig.func1: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xe18061)
(*Context).Next: c.handlersc.index
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 (0xe229be)
serveError: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:438 (0xe225e4)
(*Engine).handleHTTPRequest: serveError(c, http.StatusNotFound, default404Body)
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:367 (0xe21f74)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
D:/Go/src/net/http/server.go:2843 (0xbeeda9)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
D:/Go/src/net/http/server.go:1925 (0xbea3cc)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
D:/Go/src/runtime/asm_amd64.s:1374 (0x841dc0)
goexit: BYTE $0x90 // NOP

from eagle.

957651480 avatar 957651480 commented on August 22, 2024

我看了,你那边应该error/404.html 没有提交到master 上来吧

from eagle.

957651480 avatar 957651480 commented on August 22, 2024

然后我拷贝了模板的index.html 复制到templates/error/404.html ,访问不存在的路由就没有问题了,但如果不继承模板又会报错
报错如下
2020/12/17 22:45:48 [Recovery] 2020/12/17 - 22:45:48 panic recovered:
GET /err HTTP/1.1
Host: localhost:8080
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cache-Control: max-age=0
Connection: keep-alive
Cookie: Hm_lvt_1d2d61263f13e4b288c8da19ad3ff56d=1601001166
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: cross-site
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36

TemplateEngine execute template error: html/template:layouts/master:23:15: no such template "content"
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:842 (0x159c124)
(*Context).Render: panic(err)
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:851 (0x159c1e4)
(*Context).HTML: c.Render(code, instance)
D:/goworkspace/src/snake/app/web/error.go:11 (0x1909664)
Error404: c.HTML(http.StatusOK, "error/404", gin.H{
D:/goworkspace/src/snake/router/web.go:24 (0x1909665)
LoadWebRouter.func1: web.Error404(c)
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1598061)
(*Context).Next: c.handlersc.index
D:/goworkspace/src/snake/router/middleware/requestid.go:28 (0x18fb74c)
RequestID.func1: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1598061)
(*Context).Next: c.handlersc.index
D:/goworkspace/src/snake/router/middleware/header.go:24 (0x18fa4e4)
Options: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1598061)
(*Context).Next: c.handlersc.index
D:/goworkspace/src/snake/router/middleware/header.go:16 (0x18fa476)
NoCache: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1598061)
(*Context).Next: c.handlersc.index
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:83 (0x15ac726)
RecoveryWithWriter.func1: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1598061)
(*Context).Next: c.handlersc.index
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0x15ab813)
LoggerWithConfig.func1: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x1598061)
(*Context).Next: c.handlersc.index
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 (0x15a29be)
serveError: c.Next()
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:438 (0x15a25e4)
(*Engine).handleHTTPRequest: serveError(c, http.StatusNotFound, default404Body)
D:/goworkspace/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:367 (0x15a1f74)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
D:/Go/src/net/http/server.go:2843 (0x136eda9)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
D:/Go/src/net/http/server.go:1925 (0x136a3cc)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
D:/Go/src/runtime/asm_amd64.s:1374 (0xfc1dc0)
goexit: BYTE $0x90 // NOP

from eagle.

qloog avatar qloog commented on August 22, 2024

对,之前没有添加会报错,已添加。

from eagle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.