receiver

package module
v0.0.0-...-bd552e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2018 License: MIT Imports: 5 Imported by: 2

README

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


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetData

func SetData(data interface{}, r *http.Request) error

Set data value from http.Request.Form

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL