Skip to content

Commit e815e3c

Browse files
committed
updated readme and doc examples with []string
1 parent d1bf92b commit e815e3c

File tree

2 files changed

+53
-49
lines changed

2 files changed

+53
-49
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ import (
3434
)
3535

3636
type formParams struct {
37-
Name string `param:"name"`
38-
Age int `param:"age"`
39-
Height float64 `param:"height"`
40-
Married bool `param:"married"`
37+
Name string `param:"name"`
38+
Age int `param:"age"`
39+
Height float64 `param:"height"`
40+
Married bool `param:"married"`
41+
OtherNames []string `param:"other_names"`
4142
}
4243

4344
func main() {
@@ -46,6 +47,7 @@ func main() {
4647
reqForm.Set(`age`, `50`)
4748
reqForm.Set(`height`, `1.72`)
4849
reqForm.Set(`married`, `true`)
50+
reqForm[`other_names`] = []string{`form_test`, `form_example`}
4951

5052
req, err := http.NewRequest(`POST`, `https://nipuna.lk`, strings.NewReader(reqForm.Encode()))
5153
if err != nil {
@@ -61,8 +63,8 @@ func main() {
6163
log.Fatalln(fmt.Errorf(`error extracting forms due to %v`, err))
6264
}
6365

64-
fmt.Println(fmt.Sprintf(`request forms := %v`, forms))
65-
//Output : request forms := {form_name 50 1.72 true}
66+
fmt.Println(fmt.Sprintf(`request forms := %v`, forms))
67+
//Output : request forms := {form_name 50 1.72 true [form_test form_example]}
6668
}
6769
```
6870

doc.go

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,51 @@
88
//
99
// Sample code example code to extract request form values using paramex is shown below.
1010
//
11-
// package main
12-
//
13-
// import (
14-
// "fmt"
15-
// "log"
16-
// "net/http"
17-
// "net/url"
18-
// "strings"
19-
//
20-
// "github.com/senpathi/paramex"
21-
// )
22-
//
23-
// type formParams struct {
24-
// Name string `param:"name"`
25-
// Age int `param:"age"`
26-
// Height float64 `param:"height"`
27-
// Married bool `param:"married"`
28-
// }
29-
//
30-
// func main() {
31-
// reqForm := url.Values{}
32-
// reqForm.Set(`name`, `form_name`)
33-
// reqForm.Set(`age`, `50`)
34-
// reqForm.Set(`height`, `1.72`)
35-
// reqForm.Set(`married`, `true`)
36-
//
37-
// req, err := http.NewRequest(`POST`, `https://nipuna.lk`, strings.NewReader(reqForm.Encode()))
38-
// if err != nil {
39-
// log.Fatalln(err)
40-
// }
41-
// req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
42-
//
43-
// forms := formParams{}
44-
// extractor := paramex.NewParamExtractor()
45-
//
46-
// err = extractor.ExtractForms(&forms, req)
47-
// if err != nil {
48-
// log.Fatalln(fmt.Errorf(`error extracting forms due to %v`, err))
49-
// }
50-
//
51-
// fmt.Println(fmt.Sprintf(`request forms := %v`, forms))
52-
// //Output : request forms := {form_name 50 1.72 true}
53-
// }
11+
// package main
12+
//
13+
// import (
14+
// "fmt"
15+
// "log"
16+
// "net/http"
17+
// "net/url"
18+
// "strings"
19+
//
20+
// "github.com/senpathi/paramex"
21+
// )
22+
//
23+
// type formParams struct {
24+
// Name string `param:"name"`
25+
// Age int `param:"age"`
26+
// Height float64 `param:"height"`
27+
// Married bool `param:"married"`
28+
// OtherNames []string `param:"other_names"`
29+
// }
30+
//
31+
// func main() {
32+
// reqForm := url.Values{}
33+
// reqForm.Set(`name`, `form_name`)
34+
// reqForm.Set(`age`, `50`)
35+
// reqForm.Set(`height`, `1.72`)
36+
// reqForm.Set(`married`, `true`)
37+
// reqForm[`other_names`] = []string{`form_test`, `form_example`}
38+
//
39+
// req, err := http.NewRequest(`POST`, `https://nipuna.lk`, strings.NewReader(reqForm.Encode()))
40+
// if err != nil {
41+
// log.Fatalln(err)
42+
// }
43+
// req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
44+
//
45+
// forms := formParams{}
46+
// extractor := paramex.NewParamExtractor()
47+
//
48+
// err = extractor.ExtractForms(&forms, req)
49+
// if err != nil {
50+
// log.Fatalln(fmt.Errorf(`error extracting forms due to %v`, err))
51+
// }
52+
//
53+
// fmt.Println(fmt.Sprintf(`request forms := %v`, forms))
54+
// //Output : request forms := {form_name 50 1.72 true [form_test form_example]}
55+
// }
5456
//
5557
// Examples codes to extract http headers, url query values and form values are implemented in
5658
// https://github.com/senpathi/paramex/tree/master/example directory.

0 commit comments

Comments
 (0)