How to add favicon.ico on beego?

huangapple go评论109阅读模式
英文:

How to add favicon.ico on beego?

问题

以下是翻译好的内容:

我的 routers/default.go 文件中,我尝试使用原始的 Go 解决方案,但是失败了,这段代码无法编译。我不知道如何用 faviconHandler 替换路由器:

  1. func faviconHandler(w http.ResponseWriter, r *http.Request) {
  2. http.ServeFile(w, r, "static/img/favicon.ico")
  3. }
  4. func init() {
  5. beego.Router("/", &controllers.MainController{})
  6. beego.Router("/favicon.ico", faviconHandler) // 这段代码无法工作
  7. }
英文:

my routers/default.go, I'm trying to use the original Go solution, but failed, this code can't compiled. I don't know how to replace the router with faviconHandler:

  1. func faviconHandler(w http.ResponseWriter, r *http.Request) {
  2. http.ServeFile(w, r, "static/img/favicon.ico")
  3. }
  4. func init() {
  5. beego.Router("/", &controllers.MainController{})
  6. beego.Router("/favicon.ico", faviconHandler) // this doesn't work
  7. }

答案1

得分: 1

我发现至少有一种方法:将其嵌入到index.tpl中。

  1. bee new newapp
  2. cd $GOPATH/src/newapp
  3. bee run # 你将看到一个蜜蜂的favicon。

将$GOPATH/src/view/index.tpl中的嵌入文本修改为你自己的,这里是一个Linux脚本

  1. cd views
  2. # 假设你已经将favicon.ico放在此目录中
  3. base64 -w0 favicon.ico > favicon.b64
  4. cp index.tpl index.tpl.old
  5. sed 's/base64,.*"/base64,\n"/' index.tpl.old | sed '7r favicon.b64' > index.tpl
  6. # rm favicon.ico favicon.b64 index.tpl.old # 删除临时文件
英文:

I found there is at least one method: embedded into index.tpl.

  1. bee new newapp
  2. cd $GOPATH/src/newapp
  3. bee run # you will see the favicon of a bee.

Modify the embedded text in $GOPATH/src/view/index.tpl to yours, here is a linux script

  1. cd views
  2. # assume you have put the favicon.ico in this directory
  3. base64 -w0 favicon.ico > favicon.b64
  4. cp index.tpl index.tpl.old
  5. sed 's/base64,.*"/base64,\n"/' index.tpl.old | sed '7r favicon.b64' > index.tpl
  6. # rm favicon.ico favicon.b64 index.tpl.old # remove the temp file

答案2

得分: 0

将您的favicon.ico文件放在./static/目录中。

请查看此链接https://beego.me/docs/quickstart/static.md

英文:

Put your favicon.ico file at ./static/ directory

Check this https://beego.me/docs/quickstart/static.md

huangapple
  • 本文由 发表于 2017年6月23日 15:41:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/44715768.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定