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) string

Parameters & Attributes

NameTypeDescription
data[]byteInput 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)  }}
Go Reference