Skip to content

get the request value into given struct with validation

License

Notifications You must be signed in to change notification settings

Gujarats/receiver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

receiver Build Status

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)
}

About

get the request value into given struct with validation

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages