favicon设置

目录结构

主目录favicon

  1. —— static
  2. —— favicons
  3. —— favicon.ico
  4. —— main.go

示例代码

main.go

  1. package main
  2. import (
  3. "github.com/kataras/iris"
  4. )
  5. func main() {
  6. app := iris.New()
  7. //这将为./static/favicons/favicon.ico提供服务:localhost:080/favicon.ico
  8. app.Favicon("./static/favicons/favicon.ico")
  9. // app.Favicon("./static/favicons/favicon.\\.ico", "/favicon_16_16.ico")
  10. // 这将为 ./static/favicons/favicon.ico 提供服务: localhost:8080/favicon_16_16.ico
  11. app.Get("/", func(ctx iris.Context) {
  12. ctx.HTML(`<a href="/favicon.ico"> press here to see the favicon.ico</a>.
  13. At some browsers like chrome, it should be visible at the top-left side of the browser's window,
  14. because some browsers make requests to the /favicon.ico automatically,
  15. so iris serves your favicon in that path too (you can change it).`)
  16. }) //如果您没有显示favicon,请尝试清除浏览器的缓存。
  17. app.Run(iris.Addr(":8080"))
  18. }