Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DetCgyMap = map[string]FileCategory{ "image/x-icon": FileCategoryImage, "image/bmp": FileCategoryImage, "image/gif": FileCategoryImage, "image/webp": FileCategoryImage, "image/png": FileCategoryImage, "image/jpeg": FileCategoryImage, "video/webm": FileCategoryVideo, "video/mp4": FileCategoryVideo, "video/avi": FileCategoryVideo, "application/ogg": FileCategoryVideo, "audio/mpeg": FileCategoryAudio, "audio/aiff": FileCategoryAudio, "audio/midi": FileCategoryAudio, "audio/wave": FileCategoryAudio, "application/wasm": FileCategoryWasm, }
DetCgyMap is a map of file extensions to their corresponding FileCategory.
var ExtCgyMap = map[string]FileCategory{ "webp": FileCategoryImage, "jpg": FileCategoryImage, "png": FileCategoryImage, "gif": FileCategoryImage, "bmp": FileCategoryImage, "ico": FileCategoryImage, "webm": FileCategoryVideo, "mp4": FileCategoryVideo, "avi": FileCategoryVideo, "ogg": FileCategoryVideo, "mpeg": FileCategoryAudio, "mp3": FileCategoryAudio, "aiff": FileCategoryAudio, "midi": FileCategoryAudio, "wav": FileCategoryAudio, "wasm": FileCategoryWasm, }
ExtCgyMap is a map of file extensions to their corresponding FileCategory.
Functions ¶
func FileTypeByDetectContentType ¶
FileTypeByDetectContentType detects the content type of the given byte slice.
func SaveUploadedFileWithCheck ¶ added in v0.3.16
func SaveUploadedFileWithCheck(file *multipart.FileHeader, dst string, allowCategorys ...FileCategory) error
SaveUploadedFileWithCheck saves an uploaded file while performing checks.
Types ¶
type FileCategory ¶
type FileCategory int32
FileCategory represents the category of a file.
const ( FileCategoryNil FileCategory = iota FileCategoryImage FileCategoryVideo FileCategoryAudio FileCategoryWasm )
Constants representing the different file categories.
func GetFileCategoryByDet ¶
func GetFileCategoryByDet(det string) FileCategory
GetFileCategoryByDet returns the FileCategory for a given detection string.
func GetFileCategoryByExt ¶
func GetFileCategoryByExt(ext string) FileCategory
GetFileCategoryByExt returns the FileCategory for a given file extension.
func (FileCategory) Ok ¶
func (t FileCategory) Ok(filepath string) bool
The Ok function determines whether the given file path belongs to the specified file category. Parameters:
- filepath: File path
Return value:
- bool: Returns true if the file path is of the specified file category; otherwise, returns false.
func (FileCategory) OkBs ¶ added in v0.3.15
func (t FileCategory) OkBs(r []byte) bool
OkBs checks if the given byte slice belongs to the specified file category. It first detects the content type of the byte slice using FileTypeByDetectContentType. Then it checks if the detected file category matches the specified file category. Returns true if the byte slice belongs to the specified file category, otherwise false.
func (FileCategory) OkRead ¶
func (t FileCategory) OkRead(r io.Reader) bool
The OkRead function determines whether the content from the provided io.Reader belongs to the specified file category. Parameters:
- r: io.Reader
Return value:
- bool: Returns true if the content from the io.Reader is of the specified file category; otherwise, returns false.
type FileTypeFunc ¶
FileTypeFunc is a function type that takes a byte slice and returns a string.