Skip to content

Instantly share code, notes, and snippets.

@nguyendangminh
Last active August 21, 2023 16:05
Show Gist options
  • Save nguyendangminh/bd6e1e01df3c6cff139b1609fc1a646c to your computer and use it in GitHub Desktop.
Save nguyendangminh/bd6e1e01df3c6cff139b1609fc1a646c to your computer and use it in GitHub Desktop.
Serve favicon.ico in Golang
...
func faviconHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "relative/path/to/favicon.ico")
}
...
func main() {
http.HandleFunc("/favicon.ico", faviconHandler)
}
@jm-janzen
Copy link

Now that I see the solution, I'm embarrassed I even thought to search for it. Still, thank you for posting this.

@KaiserGald
Copy link

Thanks, I feel like a derp. Took me an hour to figure out why I couldn't get the favicon to show...

@farhany
Copy link

farhany commented Mar 2, 2018

If there was an easier way to do this with rice... I do have the method now.

@sh0seo
Copy link

sh0seo commented Aug 7, 2020

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment