Route upserts a route to the API definition.
(method, pattern string)
| 187 | |
| 188 | // Route upserts a route to the API definition. |
| 189 | func (api *API) Route(method, pattern string) (r *Route) { |
| 190 | methodToRoute, ok := api.Routes[Pattern(pattern)] |
| 191 | if !ok { |
| 192 | methodToRoute = make(MethodToRoute) |
| 193 | api.Routes[Pattern(pattern)] = methodToRoute |
| 194 | } |
| 195 | route, ok := methodToRoute[Method(method)] |
| 196 | if !ok { |
| 197 | route = &Route{ |
| 198 | Method: Method(method), |
| 199 | Pattern: Pattern(pattern), |
| 200 | Models: Models{ |
| 201 | Responses: make(map[int]Model), |
| 202 | }, |
| 203 | Params: Params{ |
| 204 | Path: make(map[string]PathParam), |
| 205 | Query: make(map[string]QueryParam), |
| 206 | }, |
| 207 | } |
| 208 | methodToRoute[Method(method)] = route |
| 209 | } |
| 210 | return route |
| 211 | } |
| 212 | |
| 213 | // Get defines a GET request route for the given pattern. |
| 214 | func (api *API) Get(pattern string) (r *Route) { |