CreateRequest returns a request key'd off of the name given. The params are merged into the URL and body is set as the request body.
(name string, params Params, body io.Reader)
| 118 | // CreateRequest returns a request key'd off of the name given. The params are |
| 119 | // merged into the URL and body is set as the request body. |
| 120 | func (router Router) CreateRequest(name string, params Params, body io.Reader) (*http.Request, error) { |
| 121 | route, ok := router.routes[name] |
| 122 | if !ok { |
| 123 | return &http.Request{}, fmt.Errorf("no route exists with the name %s", name) |
| 124 | } |
| 125 | |
| 126 | uri, err := route.CreatePath(params) |
| 127 | if err != nil { |
| 128 | return &http.Request{}, err |
| 129 | } |
| 130 | |
| 131 | url, err := router.urlFrom(router.baseURL, uri) |
| 132 | if err != nil { |
| 133 | return &http.Request{}, err |
| 134 | } |
| 135 | |
| 136 | return http.NewRequest(route.Method, url, body) |
| 137 | } |
| 138 | |
| 139 | func (Router) urlFrom(resource string, uri string) (string, error) { |
| 140 | u, err := url.Parse(resource) |
no test coverage detected