dqiatvbi61502 2017-06-23 07:41 采纳率: 0%
浏览 641
已采纳

如何在beego上添加favicon.ico?

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                 
}
  • 写回答

2条回答 默认 最新

  • dongqi4085 2017-07-04 03:39
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?