| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package frontend | 5 package frontend |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "html/template" | 10 "html/template" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 return -1, fmt.Errorf("limit parameter value %q is less than 0",
sLimit) | 245 return -1, fmt.Errorf("limit parameter value %q is less than 0",
sLimit) |
| 246 } | 246 } |
| 247 return limit, nil | 247 return limit, nil |
| 248 } | 248 } |
| 249 | 249 |
| 250 // pagedURL returns a self URL with the given cursor and limit paging options. | 250 // pagedURL returns a self URL with the given cursor and limit paging options. |
| 251 // if limit is set to 0, then inherit whatever limit is set in request. If | 251 // if limit is set to 0, then inherit whatever limit is set in request. If |
| 252 // both are unspecified, then limit is omitted. | 252 // both are unspecified, then limit is omitted. |
| 253 func pagedURL(r *http.Request, limit int, cursor string) string { | 253 func pagedURL(r *http.Request, limit int, cursor string) string { |
| 254 if limit == 0 { | 254 if limit == 0 { |
| 255 » » var err error | 255 » » limit, _ = GetLimit(r) // This returns -1 on error. |
| 256 » » limit, err = GetLimit(r) | |
| 257 » » if err != nil { | |
| 258 » » » // This should not happen because the handler should've
already validated the | |
| 259 » » » // limit earlier in the process. | |
| 260 » » » panic(err) | |
| 261 » » } | |
| 262 if limit < 0 { | 256 if limit < 0 { |
| 263 limit = 0 | 257 limit = 0 |
| 264 } | 258 } |
| 265 } | 259 } |
| 266 values := r.URL.Query() | 260 values := r.URL.Query() |
| 267 switch cursor { | 261 switch cursor { |
| 268 case "EMPTY": | 262 case "EMPTY": |
| 269 values.Del("cursor") | 263 values.Del("cursor") |
| 270 case "": | 264 case "": |
| 271 // Do nothing, just leave the cursor in. | 265 // Do nothing, just leave the cursor in. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 c.Context = withRequest(c.Context, c.Request) | 366 c.Context = withRequest(c.Context, c.Request) |
| 373 next(c) | 367 next(c) |
| 374 } | 368 } |
| 375 | 369 |
| 376 func getRequest(c context.Context) *http.Request { | 370 func getRequest(c context.Context) *http.Request { |
| 377 if req, ok := c.Value(&requestKey).(*http.Request); ok { | 371 if req, ok := c.Value(&requestKey).(*http.Request); ok { |
| 378 return req | 372 return req |
| 379 } | 373 } |
| 380 panic("No http.request found in context") | 374 panic("No http.request found in context") |
| 381 } | 375 } |
| OLD | NEW |