如何在beego上添加favicon.ico?

林志强:

我的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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章