Standard library / net/http
http.DetectContentType()
Sniff at most 512 bytes of data for a media type; not a security validator. Expected stdout: 'text/plain; charset=utf-8\n'.
Formal Syntax & Structure
go syntaxgo
func DetectContentType(data []byte) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | []byte | Input bytes or form values, as declared. |
Return Value
string
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http")
func main() { fmt.Println(http.DetectContentType([]byte("hello"))) }
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}