Golang“ net / http”错误:未定义:DetectContentType

The "net/http" package implements the function DetectContentType

http://golang.org/pkg/net/http/#DetectContentType

but when I try to use it, i get the error undefined: DetectContentType

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
)

func main() {
    res, err := http.Get("http://www.google.com/robots.txt")
    if err != nil {
        log.Fatal(err)
    }

    robots, err := ioutil.ReadAll(res.Body)
    res.Body.Close()
    if err != nil {
        log.Fatal(err)
    }

    fileType := DetectContentType(robots)

        fmt.Println("FileType: ", fileType)
}

https://play.golang.org/p/WJDuU8Xx-5

What am I doing wrong?

It is part of the "net/http" package therefore you have to write,

http.DetectContentType(robots)

Note that if you wanted to use this function in this way you could change your import statement as such:

import (
   ...
   . "net/http"
)