https://github.com/firmanmm/greb
Golang HTTP Request Binding
https://github.com/firmanmm/greb
golang http
Last synced: 5 months ago
JSON representation
Golang HTTP Request Binding
- Host: GitHub
- URL: https://github.com/firmanmm/greb
- Owner: firmanmm
- License: mit
- Created: 2021-09-19T13:42:35.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-24T15:20:08.000Z (about 2 years ago)
- Last Synced: 2025-01-31T19:40:13.324Z (about 1 year ago)
- Topics: golang, http
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
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.
|Type|Description|
| ------------- |:-------------|
|query|Taken from query param|
|form|Taken from body|
|json|Taken from body|
|header|Taken from header|
|cookie|Taken from cookie|
### Binding Data Type
Binding data type is the data type to bind to.
|Type|Description|
| ------------- |:-------------|
|int|Integer value|
|float|Decimal value|
|string|Literally string|
|bool|`true` or `false`|
|bytes|Uses 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.
|Tag|Description|
| ------------- |:-------------|
|validate|Perform data validation based on golang validator library|
|alias|Override key used to get data|