MCPcopy
hub / github.com/dgraph-io/dgraph / parseDuration

Function parseDuration

dgraph/cmd/alpha/http.go:123–135  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
123func 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
137func loginHandler(w http.ResponseWriter, r *http.Request) {
138 if commonHandler(w, r) {

Callers 1

queryHandlerFunction · 0.85

Calls 2

GetMethod · 0.65
QueryMethod · 0.45

Tested by

no test coverage detected