MCPcopy
hub / github.com/beego/beego / ExampleWrapperFromForm

Function ExampleWrapperFromForm

server/web/generic_wrapper_test.go:82–105  ·  view source on GitHub ↗

ExampleWrapperFromForm demonstrates the usage of WrapperFromForm to handle form data.

()

Source from the content-addressed store, hash-verified

80
81// ExampleWrapperFromForm demonstrates the usage of WrapperFromForm to handle form data.
82func ExampleWrapperFromForm() {
83 app := NewHttpServerWithCfg(newBConfig())
84 //app.Cfg.CopyRequestBody = true
85 path := sendUrl
86 // Use wrapper
87 app.Post(path, Wrapper(addUser))
88
89 formData := url.Values{}
90 formData.Set("name", "jack")
91
92 req := httptest.NewRequest("POST", path, strings.NewReader(formData.Encode()))
93 req.Header.Set(contentType, context.ApplicationForm)
94 req.Header.Set(accept, "*/*")
95
96 w := httptest.NewRecorder()
97 app.Handlers.ServeHTTP(w, req)
98
99 // Output the result
100 fmt.Println(w.Code)
101 fmt.Println(w.Body.String())
102 // Output:
103 // 200
104 // ["jack",0]
105}
106
107// ExampleWrapper demonstrates the usage of Wrapper to handle requests.
108func ExampleWrapper() {

Callers

nothing calls this directly

Calls 7

NewHttpServerWithCfgFunction · 0.85
newBConfigFunction · 0.85
WrapperFunction · 0.85
ServeHTTPMethod · 0.80
PostMethod · 0.65
SetMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…