[Go] Provide http service with two requests and process favicon.ico

When the http package is used, the mode processing of /this root path is registered, and the browser will automatically request favicon.ico. Be careful to handle it, otherwise there will be two requests

func main() {
    log.Println( " listen on 8080...\r\ nAccess : http://127.0.0.1:8080 " )
     // root path 
    http.HandleFunc( " / " , index)
        http.ListenAndServe( " :8080 " , nil)
}

// Home page jump 
func index(w http.ResponseWriter, r * http.Request) {
     if r.URL.RequestURI() == " /favicon.ico " {
         return
    }
}    

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *