我将把静态文件打包成Golang可执行文件。如何在Gin中使用go-bindata (或go-bindata-assetfs)?在互联网上有一些缺失的例子。
发布于 2018-08-23 08:04:29
基本上,您需要使用go-bindata滚动您自己的静态文件处理程序...
func bindataStaticHandler(c *gin.Context) {
path := c.Param("filepath")
data, err := Asset("pub/style/foo.css")
if err != nil {
// Asset was not found.
}
// Write asset
c.Writer.Write(data)
// Handle errors here too and cache headers
}然后声明路由(在创建gin引擎之后)
router.GET("/static/*filepath", bindataStaticHandler)这是非常基础的东西,但只是为了向您展示如何去做。
https://stackoverflow.com/questions/51974004
复制相似问题