I'm trying to add <title>Go</title>
to my code example:
package main
import (
"fmt"
"net/http"
"os"
)
func favicon(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "favicon.ico")
}
func sayhelloName(w http.ResponseWriter, r *http.Request) {
hostname, _ := os.Hostname()
fmt.Fprintf(w, "
System info:
Hostname [pod name]: %s", hostname)
fmt.Fprintf(w, "
Current URL: %s
", r.Host)
}
func main() {
http.HandleFunc("/favicon.ico", favicon)
http.HandleFunc("/", sayhelloName)
http.ListenAndServe(":80", nil)
}
I tried to add like:
fmt.Fprintf(w, "<title>Go</title>")
. It works but make mess with strings next to. I wouldn't like to use html template only to add title to page. Is there any ways to add title in one string?