如何获得带有媒体子类型的http响应的MIME类型?

I want to store MIME type of the response obtained from GET request. I have used the DetectContentType function but it gives me text/plain; charset=utf-8 for both js and css resource. I have to distinguish the filetype for each url and I'm depending on MIME type for that purpose.

response, error := http.Get(url) 
if error == nil { 
    contentType := response.Header.Get("Content-Type") 
    // ... 
}

Only gives me content type.

Sounds like you could use Go's mime package. The TypeByExtension method in the mime package might suit your needs. https://golang.org/pkg/mime/#TypeByExtension

I believe this uses the host system's mime type table. It is possible that the mime type determined by this method could be different than the mime type reported by the remote server.

import "mime"

func DetermineMimeType (fileExtension string) string {
    return mime.TypeByExtension(fileExtension)
}

Be sure to pass in the full file extension including the period, for example ".js" or ".css". Just to cover all the cases, if you can't determine the file's extension or this method doesn't return a mime type then perhaps default to the mime type reported by the remote server.