my routers/default.go,我尝试使用原始的 Go 解决方案,但失败了,这段代码无法编译。我不知道如何用 faviconHandler 替换路由器:
func faviconHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "static/img/favicon.ico")
}
func init() {
beego.Router("/", &controllers.MainController{})
beego.Router("/favicon.ico", faviconHandler) // this doesn't work
}
最佳答案
我发现至少有一种方法:嵌入到 index.tpl 中。
bee new newapp
cd $GOPATH/src/newapp
bee run # you will see the favicon of a bee.
将$GOPATH/src/view/index.tpl中的嵌入文本修改成你的,这里是linux脚本
cd views
# assume you have put the favicon.ico in this directory
base64 -w0 favicon.ico > favicon.b64
cp index.tpl index.tpl.old
sed 's/base64,.*"/base64,\n"/' index.tpl.old | sed '7r favicon.b64' > index.tpl
# rm favicon.ico favicon.b64 index.tpl.old # remove the temp file
关于go - 如何在beego上添加favicon.ico?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44715768/