how to add a logo to website icon
package main
import (
"html/template"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.New("index").Parse(`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Your Website Title</title>
<link rel="icon" href="/static/favicon.ico" type="image/x-icon">
</head>
<body>
<!-- Your website content goes here -->
</body>
</html>
`)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = tmpl.Execute(w, nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func main() {
http.HandleFunc("/", handler)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.ListenAndServe(":8080", nil)
}
Create a folder named "static" in the same directory as your Go code.
Place your favicon.ico file (which should be your logo) inside the "static" folder.
Replace "Your Website Title" in the HTML template with the actual title of your website.
Adjust the
handler
function to include your website content between the<body>
tags.Run your Go program, and the website will be accessible at http://localhost:8080.
The favicon.ico with your logo will be displayed in the browser tab.