gin路由打开html页面,gin 无法返回html

如题:

package main

import (

"github.com/gin-gonic/gin"

"net/http"

)

func main() {

r := gin.Default()

r.GET("/login", func(context *gin.Context) {

context.HTML(http.StatusOK, "login.html", gin.H{})

})

r.Run(":8080")

}

{{define "login.html"}}

Title

用户名:

密码:

{{end}}

报错

runtime error: invalid memory address or nil pointer dereference

C:/Go/src/runtime/panic.go:513 (0x42cc46)

gopanic: reflectcall(nil, unsafe.Pointer(d.fn), deferArgs(d), uint32(d.siz), uint32(d.siz))

C:/Go/src/runtime/panic.go:82 (0x42bd44)

panicmem: panic(memoryError)

C:/Go/src/runtime/signal_windows.go:204 (0x43fda0)

sigpanic: panicmem()

C:/Go/gocode/src/github.com/gin-gonic/gin/context.go:764 (0x94e4ec)

(*Context).HTML: instance := c.engine.HTMLRender.Instance(name, obj)

C:/Go/gocode/src/demo/main.go:11 (0x95fa99)

main.func1: context.HTML(http.StatusOK, "login.html", gin.H{})

C:/Go/gocode/src/github.com/gin-gonic/gin/context.go:109 (0x94a8c9)

(*Context).Next: c.handlers[c.index](c)

C:/Go/gocode/src/github.com/gin-gonic/gin/recovery.go:76 (0x95d860)

RecoveryWithWriter.func1: c.Next()

C:/Go/gocode/src/github.com/gin-gonic/gin/context.go:109 (0x94a8c9)

(*Context).Next: c.handlers[c.index](c)

C:/Go/gocode/src/github.com/gin-gonic/gin/logger.go:170 (0x95cc37)

LoggerWithConfig.func1: c.Next()

C:/Go/gocode/src/github.com/gin-gonic/gin/context.go:109 (0x94a8c9)

(*Context).Next: c.handlers[c.index](c)

C:/Go/gocode/src/github.com/gin-gonic/gin/gin.go:383 (0x9542b1)

(*Engine).handleHTTPRequest: c.Next()

C:/Go/gocode/src/github.com/gin-gonic/gin/gin.go:349 (0x953ae8)

(*Engine).ServeHTTP: engine.handleHTTPRequest(c)

C:/Go/src/net/http/server.go:2741 (0x6723d1)

serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)

C:/Go/src/net/http/server.go:1847 (0x66e54c)

(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)

C:/Go/src/runtime/asm_amd64.s:1333 (0x457690)

goexit: BYTE $0x90 // NOP

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值