receiver
Get the request value into given struct with validation
let's say you have incoming request and wanted to parse the Form
from http.Request
.
You can do that by using this library.
Installation
go get github.com/Gujarats/receiver
Usage
First of all you need to create the struct for storing the data lets say you have some struct
like this :
// Note : the latitude,longitude,name,distance is the key name to get the value name
// second argument is to tell wheter the request is required or not
type Sample struct {
Lat float64 `request:"latitude,required"`
Lon float64 `request:"longitude,required"`
Name string `request:"name,required"`
Distance int64 `request:"distance,optional"`
}
func HandleFunc(w http.ResponseWriter, r *http.Request){
var sample Sample
err := receiver.SetData(&sample,r)
if err != nil {
log.Fatal(err)
}
log.Printf("sample = %+v\n",sample)
}