-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
71 lines (71 loc) · 2.03 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Package paramex is a library that binds http request parameters to a Go struct annotated with param.
//
// Description
//
// To extract http parameters (headers, url query values, form values), multiple code lines need to be written in http Handlers.
//
// But, Using Paramex http headers, url query values or form values can be extracted by calling a single function.
//
// Sample code example code to extract request form values using paramex is shown below.
//
// package main
//
// import (
// "fmt"
// "log"
// "net/http"
// "net/url"
// "strings"
//
// "github.com/senpathi/paramex"
// )
//
// type formParams struct {
// Name string `param:"name"`
// Age int `param:"age"`
// Height float64 `param:"height"`
// Married bool `param:"married"`
// OtherNames []string `param:"other_names"`
// }
//
// func main() {
// reqForm := url.Values{}
// reqForm.Set(`name`, `form_name`)
// reqForm.Set(`age`, `50`)
// reqForm.Set(`height`, `1.72`)
// reqForm.Set(`married`, `true`)
// reqForm[`other_names`] = []string{`form_test`, `form_example`}
//
// req, err := http.NewRequest(`POST`, `https://nipuna.lk`, strings.NewReader(reqForm.Encode()))
// if err != nil {
// log.Fatalln(err)
// }
// req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
//
// forms := formParams{}
// extractor := paramex.NewParamExtractor()
//
// err = extractor.ExtractForms(&forms, req)
// if err != nil {
// log.Fatalln(fmt.Errorf(`error extracting forms due to %v`, err))
// }
//
// fmt.Println(fmt.Sprintf(`request forms := %v`, forms))
// //Output : request forms := {form_name 50 1.72 true [form_test form_example]}
// }
//
// Examples codes to extract http headers, url query values and form values are implemented in
// https://github.com/senpathi/paramex/tree/master/example directory.
//
// Supported parameter types
//
// - string
// - bool
// - int32
// - int
// - int64
// - float32
// - float64
// - []string (only for form values and query values)
// - https://github.com/google/uuid
package paramex