filechecker

package module
v0.0.0-...-da4f3ee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

README

FileChecker

Utility to check whether files (e.g. uploaded) are of the authorised types before saving on disk

Usage

var uploadedFile *multipart.FileHeader

fc := GetFileChecker(uploadedFile)
if !fc.IsAuthorised() {
    fmt.Println("File not authorised")
}

Documentation

Index

Constants

View Source
const (
	TypeAPPLICATION = "Application"
	TypeARCHIVE     = "Archive"
	TypeAUDIO       = "Audio"
	TypeDOCUMENTS   = "Documents"
	TypeFONT        = "Font"
	TypeIMAGE       = "Image"
	TypeVIDEO       = "Video"

	ExtAppDEX  = "dex"
	ExtAppDEY  = "dey"
	ExtAppWASM = "wasm"

	ExtArchive7Z     = "7z"
	ExtArchiveZ      = "Z"
	ExtArchiveAR     = "ar"
	ExtArchiveBZ2    = "bz2"
	ExtArchiveCAB    = "cab"
	ExtArchiveCRX    = "crx"
	ExtArchiveDCM    = "dcm"
	ExtArchiveDEB    = "deb"
	ExtArchiveELF    = "elf"
	ExtArchiveEOT    = "eot"
	ExtArchiveEPUB   = "epub"
	ExtArchiveEXE    = "exe"
	ExtArchiveGZ     = "gz"
	ExtArchiveISO    = "iso"
	ExtArchiveLZ     = "lz"
	ExtArchiveNES    = "nes"
	ExtArchivePDF    = "pdf"
	ExtArchivePS     = "ps"
	ExtArchiveRAR    = "rar"
	ExtArchiveRPM    = "rpm"
	ExtArchiveRTF    = "rtf"
	ExtArchiveSQLITE = "sqlite"
	ExtArchiveSWF    = "swf"
	ExtArchiveTAR    = "tar"
	ExtArchiveXZ     = "xz"
	ExtArchiveZIP    = "zip"
	ExtArchiveZSTD   = "zstd"

	ExtAudioAAC  = "aac"
	ExtAudioAIFF = "aiff"
	ExtAudioAMR  = "amr"
	ExtAudioFLAC = "flac"
	ExtAudioM4A  = "m4a"
	ExtAudioMID  = "mid"
	ExtAudioMP3  = "mp3"
	ExtAudioOGG  = "ogg"
	ExtAudioWAV  = "wav"

	ExtDocDOC  = "doc"
	ExtDocDOCX = "docx"
	ExtDocPPT  = "ppt"
	ExtDocPPTX = "pptx"
	ExtDocXLS  = "xls"
	ExtDocXLSX = "xlsx"

	ExtFontOTF   = "otf"
	ExtFontTTF   = "ttf"
	ExtFontWOFF  = "woff"
	ExtFontWOFF2 = "woff2"

	ExtImgBMP  = "bmp"
	ExtImgCR2  = "cr2"
	ExtImgDWG  = "dwg"
	ExtImgGIF  = "gif"
	ExtImgHEIF = "heif"
	ExtImgICO  = "ico"
	ExtImgJPG  = "jpg"
	ExtImgJXR  = "jxr"
	ExtImgPNG  = "png"
	ExtImgPSD  = "psd"
	ExtImgTIF  = "tif"
	ExtImgWEBP = "webp"

	ExtVideo3GP  = "3gp"
	ExtVideoAVI  = "avi"
	ExtVideoFLV  = "flv"
	ExtVideoM4V  = "m4v"
	ExtVideoMKV  = "mkv"
	ExtVideoMOV  = "mov"
	ExtVideoMP4  = "mp4"
	ExtVideoMPG  = "mpg"
	ExtVideoWEBM = "webm"
	ExtVideoWMV  = "wmv"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileChecker

type FileChecker struct {
	// contains filtered or unexported fields
}

func GetFileChecker

func GetFileChecker(file *multipart.FileHeader) *FileChecker

GetFileChecker returns an instance of FileChecker.

func (*FileChecker) IsAuthorised

func (fc *FileChecker) IsAuthorised() bool

IsAuthorised tells us whether the file is authorised (type and extension).

func (*FileChecker) SetExtensions

func (fc *FileChecker) SetExtensions(extensions []string)

SetExtensions sets authorised extensions.

func (*FileChecker) SetFile

func (fc *FileChecker) SetFile(file *multipart.FileHeader)

SetFile sets the file to be checked.

func (*FileChecker) UnsetExtensions

func (fc *FileChecker) UnsetExtensions(extensions []string)

UnsetExtensions unsets types that were authorised.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL