parseDuration reads the value for given URL parameter from request and parses it into time.Duration, empty string is converted into zero value
(r *http.Request, name string)
| 121 | // parseDuration reads the value for given URL parameter from request and |
| 122 | // parses it into time.Duration, empty string is converted into zero value |
| 123 | func parseDuration(r *http.Request, name string) (time.Duration, error) { |
| 124 | value := r.URL.Query().Get(name) |
| 125 | if value == "" { |
| 126 | return 0, nil |
| 127 | } |
| 128 | |
| 129 | durationValue, err := time.ParseDuration(value) |
| 130 | if err != nil { |
| 131 | return 0, errors.Wrapf(err, "while parsing %s as time.Duration", name) |
| 132 | } |
| 133 | |
| 134 | return durationValue, nil |
| 135 | } |
| 136 | |
| 137 | func loginHandler(w http.ResponseWriter, r *http.Request) { |
| 138 | if commonHandler(w, r) { |
no test coverage detected