aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/cli
diff options
context:
space:
mode:
authorKristian Aune <kraune@verizonmedia.com>2023-05-23 15:20:38 +0200
committerKristian Aune <kraune@verizonmedia.com>2023-05-23 15:20:38 +0200
commitd82b369870a2d2e9cefa3104073db652619e8b09 (patch)
treeb6760aa16dd88151363b62a001a6de7b340e53d1 /client/go/internal/cli
parent0a8b7389de37ee1f57f84513752174f110462c24 (diff)
Support RFC3339 in visit ranges
Diffstat (limited to 'client/go/internal/cli')
-rw-r--r--client/go/internal/cli/cmd/visit.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/client/go/internal/cli/cmd/visit.go b/client/go/internal/cli/cmd/visit.go
index 10fb2743c63..1875c768c60 100644
--- a/client/go/internal/cli/cmd/visit.go
+++ b/client/go/internal/cli/cmd/visit.go
@@ -138,6 +138,18 @@ $ vespa visit --field-set "[id]" # list document IDs
return cmd
}
+func getEpoch(timeStamp string) (int64, error) {
+ t, err := strconv.ParseInt(timeStamp, 10, 64)
+ if err != nil {
+ t, err := time.Parse(time.RFC3339, timeStamp)
+ if err != nil {
+ return 0, err
+ }
+ return t.Unix(), nil
+ }
+ return t, nil
+}
+
func checkArguments(vArgs visitArgs) (res util.OperationResult) {
if vArgs.slices > 0 || vArgs.sliceId > -1 {
if !(vArgs.slices > 0 && vArgs.sliceId > -1) {
@@ -149,13 +161,13 @@ func checkArguments(vArgs visitArgs) (res util.OperationResult) {
}
// to and from will support RFC3339 format soon, add more validation then
if vArgs.from != "" {
- _, err := strconv.ParseInt(vArgs.from, 10, 64)
+ _, err := getEpoch(vArgs.from)
if err != nil {
return util.Failure("Invalid 'from' argument: '" + vArgs.from + "': " + err.Error())
}
}
if vArgs.to != "" {
- _, err := strconv.ParseInt(vArgs.to, 10, 64)
+ _, err := getEpoch(vArgs.to)
if err != nil {
return util.Failure("Invalid 'to' argument: '" + vArgs.to + "': " + err.Error())
}
@@ -336,11 +348,11 @@ func runOneVisit(vArgs *visitArgs, service *vespa.Service, contToken string) (*V
urlPath = urlPath + fmt.Sprintf("&wantedDocumentCount=%d", vArgs.chunkCount)
}
if vArgs.from != "" {
- fromSeconds, _ := strconv.ParseInt(vArgs.from, 10, 64)
+ fromSeconds, _ := getEpoch(vArgs.from)
urlPath = urlPath + fmt.Sprintf("&fromTimestamp=%d", fromSeconds*1000000)
}
if vArgs.to != "" {
- toSeconds, _ := strconv.ParseInt(vArgs.to, 10, 64)
+ toSeconds, _ := getEpoch(vArgs.to)
urlPath = urlPath + fmt.Sprintf("&toTimestamp=%d", toSeconds*1000000)
}
if vArgs.slices > 0 {