MCPcopy Create free account
hub / github.com/daodst/chat / ParseTSParam

Function ParseTSParam

clientapi/httputil/parse.go:25–39  ·  view source on GitHub ↗

ParseTSParam takes a req (typically from an application service) and parses a Time object from the req if it exists in the query parameters. If it doesn't exist, the current time is returned.

(req *http.Request)

Source from the content-addressed store, hash-verified

23// from the req if it exists in the query parameters. If it doesn't exist, the
24// current time is returned.
25func ParseTSParam(req *http.Request) (time.Time, error) {
26 // Use the ts parameter's value for event time if present
27 tsStr := req.URL.Query().Get("ts")
28 if tsStr == "" {
29 return time.Now(), nil
30 }
31
32 // The parameter exists, parse into a Time object
33 ts, err := strconv.ParseInt(tsStr, 10, 64)
34 if err != nil {
35 return time.Time{}, fmt.Errorf("param 'ts' is no valid int (%s)", err.Error())
36 }
37
38 return time.Unix(ts/1000, 0), nil
39}

Callers

nothing calls this directly

Calls 2

GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected