🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] > https://github.com/h2non/filetype ## 概述 - 通过文件的魔术数字判断 ## 示例 ``` package main import ( "fmt" "io/ioutil" "github.com/h2non/filetype" ) func main() { // Open a file descriptor file, _ := os.Open("movie.mp4") // We only have to pass the file header = first 261 bytes head := make([]byte, 261) file.Read(head) if filetype.IsImage(head) { fmt.Println("File is an image") } else { fmt.Println("Not an image") } } ```