Categorygithub.com/firmanmm/greb
repositorypackage
1.0.2
Repository: https://github.com/firmanmm/greb.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

Golang REquest Binder

An automated golang HTTP Request to struct binding. Why it exist? I don't know, i just think it will be better if we automate request binding and validation process doesn't it?

How to use

You need to create a new file with .greb extension. The greb extension is optional, but maybe we should stick with it shall we? To install the package please use go get github.com/firmanmm/greb/cmd/greb. Use greb -h to show the help. To generate the golang file use greb --in=example/simple/simple.greb --out=example/simple/simple.greb.go. Here is a simple greb file definition. You should not mix form and json since it is all stored in the body.

package simple

request Simple {
    ID              query:int           validate:"required"
    GroupID         param:int           alias:"group_id"
    Name            form:string         validate:"required"
    Weight          json:float          alias:"weight"
    IsAlive         form:bool
    Authorization   header:string       validate:"required" alias:"x-authorization"
    SessionID       cookie:string
}

Supported Binding

Binding Type

Binding type is the source data to get the value.

TypeDescription
queryTaken from query param
formTaken from body
jsonTaken from body
headerTaken from header
cookieTaken from cookie

Binding Data Type

Binding data type is the data type to bind to.

TypeDescription
intInteger value
floatDecimal value
stringLiterally string
booltrue or false
bytesUses multipart when in form, and base64 in other scenario

Binding Tag

Binding Tag is to extend greb's functionality. Tags can be combined for fun.

TagDescription
validatePerform data validation based on golang validator library
aliasOverride key used to get data