Documentation
¶
Index ¶
- Constants
- func AutoCompress(mimetype string, img []byte) ([]byte, error)
- func BtoI32(val []byte) uint32
- func CompressGIF(b []byte, numColors int) ([]byte, error)
- func CompressJPEG(b []byte, quality int) ([]byte, error)
- func CompressPNG(b []byte, compressionLevel png.CompressionLevel) ([]byte, error)
- func DoesFileExist(path string) bool
- func Error(w http.ResponseWriter, sentErr HTTPError)
- func GZipBytes(content []byte) ([]byte, error)
- func GenerateETag(content []byte) (string, error)
- func GetFileLastModified(fileInfo fs.FileInfo) string
- func GetRandFromSlice[t any](slice []t) t
- func I32toB(val uint32) []byte
- func IsFileValid(name string) bool
- func IsImageSurported(contentType string) bool
- func MimeExpection(mtype *mimetype.MIME, path string) string
- func ResizeImage(img image.Image, maxWidth, maxHeight uint) image.Image
- func SendScanErr(w http.ResponseWriter, err error, noRow *string)
- type FileMime
- type HTTPError
- type ImageAccept
Constants ¶
const ( // PublicBadRequest is public message for 400 PublicBadRequest = "Something Went Wrong With your Request" // PublicServerError is public message for 500 PublicServerError = "Something Went Wrong" // PublicNotFoundError is public message for 404 PublicNotFoundError = "Nothing was Found" )
const ( // HourCache caches for an hour HourCache int = int(time.Hour) // MinuteCache caches for a minute MinuteCache int = int(time.Minute) )
const ImageMaxAge = 2 * 7 * 24 * int(time.Hour)
ImageMaxAge is the cache length (a week)
const ImageSizeLimit = 5000 * 1000
ImageSizeLimit is the size limit of all uploaded images
Variables ¶
This section is empty.
Functions ¶
func AutoCompress ¶
AutoCompress choices the method to compresses an image
func CompressGIF ¶
CompressGIF compress a GIF image
func CompressJPEG ¶
CompressJPEG compresses a JPEG image
func CompressPNG ¶
func CompressPNG(b []byte, compressionLevel png.CompressionLevel) ([]byte, error)
CompressPNG compresses a PNG image
func DoesFileExist ¶
DoesFileExist check if the file (provided by path) exists using os.Stat
func Error ¶
func Error(w http.ResponseWriter, sentErr HTTPError)
Error writes the HTTPError to the writer
func GenerateETag ¶
GenerateETag generates an ETag from content
func GetFileLastModified ¶
GetFileLastModified gets when a file has been last modified
func GetRandFromSlice ¶
func GetRandFromSlice[t any](slice []t) t
GetRandFromSlice gets an random element from a slice
func IsFileValid ¶
IsFileValid Checks if a file is legal based on it's url
func IsImageSurported ¶
IsImageSurported checks if a content-type is surported
func MimeExpection ¶
MimeExpection changes the mime based on path extension
func ResizeImage ¶
ResizeImage scales up the image if its dimensions are smaller than the desired size while maintaining the aspect ratio.
func SendScanErr ¶
func SendScanErr(w http.ResponseWriter, err error, noRow *string)
SendScanErr sends a special http error message when no rows found.
By default the noRow is "Something Went Wrong With your Request"
Types ¶
type HTTPError ¶
type HTTPError struct { Public string `json:"public"` // The public error shown in the writer Message string `json:"message"` // The more detailed message Code int `json:"-"` // The HTTP code }
HTTPError is a special json and more detailed
type ImageAccept ¶
ImageAccept is used by github.com/Blockitifluy/CoffeeCo/utility.CanImageBeAccepted
func CanImageBeAccepted ¶
func CanImageBeAccepted(r *http.Request, mimetype string) ImageAccept
CanImageBeAccepted checks: the size and content-type; for an image