Skip to content
/ sage Public

Sage - Go library designed to simplify the task of image validation

Notifications You must be signed in to change notification settings

insanXYZ/sage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image Sage is a Go library designed to simplify the task of image validation, either from *multipart.FileHeader or *os.File

Installation

  go get github.com/insanXYZ/sage

Example

Image in your pc

import (
    "github.com/insanXYZ/sage"
)

//open file in your pc with os.open
//note : giphy.gif have size 263kb
open, err := os.Open("giphy.gif")
if err != nil {
    fmt.Println(err.Error())
}

//image validation only
err := sage.Validate(open) //not error
if err != nil {
    fmt.Println(err.Error())
}

//validate format 
err := sage.Validate(open, "gif") //not error
if err != nil {
    fmt.Println(err.Error())
}

err = sage.Validate(open, "png") //error
if err != nil {
    fmt.Println(err.Error())
}

//validate size
err := sage.Validate(open, "minsize=100") //not error
if err != nil {
    fmt.Println(err.Error())
}

err = sage.Validate(open, "maxsize=100") //error
if err != nil {
    fmt.Println(err.Error())
}

//validate format and size
err = sage.Validate(open, "gif","minsize=100") //not error
if err != nil {
    fmt.Println(err.Error())
}

Web Framework

import (
    "github.com/insanXYZ/sage"
)

//Echo (https://echo.labstack.com/)
e := echo.New()

e.POST("/image-upload", func(c echo.Context) error {
    file, _ := c.FormFile("image")
    err := sage.Validate(file)
    ...
})
import (
    "github.com/insanXYZ/sage"
)

//Fiber (https://gofiber.io/)
f := fiber.New()

fiber.Post("/image-upload", func(ctx *fiber.Ctx) error {
    file, _ := ctx.FormFile("file")
    err := sage.Validate(file)
    ...
})

Tag

Tag Description
png image must be of type png
jpg image must be of type jpg
jpeg image must be of type jpeg
gif image must be of type gif
bmp image must be of type bmp
minsize images must have a certain minimum size
maxsize images must have a certain maximum size

About

Sage - Go library designed to simplify the task of image validation

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages