package main
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
//注册一个 默认的路由器
router := gin.Default()
//加载html文件
// router.LoadHTMLGlob("")
router.LoadHTMLFiles("/Users/hopkings/www/Go/src/TodoList/htmltmpl/todolist.html")
router.GET("/index", func(c *gin.Context) {
// c.HTML(http.StatusOK, "todolist.html", gin.H{"title": "already"})
c.HTML(http.StatusOK, "todolist.html", nil)
// c.HTML(code, name, obj)
})
if err := router.Run("localhost:8080"); err != nil {
log.Fatal(err)
}
}
<!DOCTYPE html>
<html>
<head>
<script src="/Users/didi/react-demos/build/react.js"></script>
<script src="/Users/didi/react-demos/build/react-dom.js"></script>
<script src="/Users/didi/react-demos/build/browser.min.js"></script>
<title>heheda</title>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('example')
);
</script>
</body>
</html>
运行之后无法正常显示todolist.html的结果,而单独点击todolist.html,效果可以正常显示,题主对于
gin.H的使用不是很理解,请老师赐教
有疑问加站长微信联系(非本文作者)