ExampleWrapperFromForm demonstrates the usage of WrapperFromForm to handle form data.
()
| 80 | |
| 81 | // ExampleWrapperFromForm demonstrates the usage of WrapperFromForm to handle form data. |
| 82 | func 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. |
| 108 | func ExampleWrapper() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…