package main
import (
"fmt"
"io/ioutil"
"github.com/h2non/filetype"
)
func main() {
buf, _ := ioutil.ReadFile("sample.jpg")
kind, _ := filetype.Match(buf)
if kind == filetype.Unknown {
fmt.Println("Unknown file type")
return
}
fmt.Printf("File type: %s. MIME: %s\n", kind.Extension, kind.MIME.Value)
}
io/ioutil's ReadFile is Deprecated since go version v1.16.
Diagnostics:
1. ioutil.ReadFile is deprecated: As of Go 1.16, this function simply calls [os.ReadFile]. [default]
2. Call of ioutil.ReadFile should be inlined [inline_call]
It would be better to use the os.ReadFile in the example instead.
io/ioutil'sReadFileis Deprecated since go version v1.16.It would be better to use the
os.ReadFilein the example instead.