-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.go
50 lines (38 loc) · 901 Bytes
/
main.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
package main
import (
"log"
"net/http"
"net/url"
"time"
"github.com/go-playground/lars"
)
const (
// used for io.LimitReader(...) for safetly!
maxBytes = 16 << 10
)
// User ...
type User struct {
ID int `form:"id"`
Name string
}
func main() {
l := lars.New()
l.Post("/user/:id", PostUser)
go simulateFormPost()
http.ListenAndServe(":3007", l.Serve())
}
// PostUser ...
func PostUser(c lars.Context) {
var user User
// first argument denotes yes or no I would like URL query parameter fields
// to be included. i.e. 'id' in route '/user/:id' should it be included.
// run, then change to false and you'll see user.ID is not populated.
if err := c.Decode(true, maxBytes, &user); err != nil {
log.Println(err)
}
log.Printf("%#v", user)
}
func simulateFormPost() {
time.Sleep(1000)
http.PostForm("http://localhost:3007/user/13", url.Values{"Name": {"joeybloggs"}})
}