2017-06-23 07:41



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:

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                 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongqi4085 dongqi4085 4年前

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

    bee new newapp
    cd $GOPATH/src/newapp
    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

    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,
    "/' index.tpl.old | sed '7r favicon.b64' > index.tpl
    # rm favicon.ico favicon.b64  index.tpl.old # remove the temp file
    点赞 评论 复制链接分享
  • dongsi073898 dongsi073898 4年前

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

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

    点赞 评论 复制链接分享