summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-08-23 19:11:24 +0200
committerJon Bratseth <bratseth@gmail.com>2021-08-23 19:11:24 +0200
commita3151ce5aa1c59a2cb25729009b41e7b61875530 (patch)
tree978bb8a78a573692c8350cd13c1ab8e52beca235 /client
parent46e5396bf12a33a3721bc7f02f23988c457f6d13 (diff)
Extract print body
Diffstat (limited to 'client')
-rw-r--r--client/go/src/cmd/document.go1
-rw-r--r--client/go/src/cmd/query.go10
-rw-r--r--client/go/src/utils/http.go1
-rw-r--r--client/go/src/utils/print.go13
4 files changed, 15 insertions, 10 deletions
diff --git a/client/go/src/cmd/document.go b/client/go/src/cmd/document.go
index 4e54e3fcb33..f5f94138fb1 100644
--- a/client/go/src/cmd/document.go
+++ b/client/go/src/cmd/document.go
@@ -58,6 +58,7 @@ func get(documentId string) {
}
func put(documentId string, jsonFile string) {
+ // TODO: Support document id in JSON, see https://docs.vespa.ai/en/reference/document-json-format.html
url, _ := url.Parse(getTarget(documentContext).document + "/document/v1/" + documentId)
header := http.Header{}
diff --git a/client/go/src/cmd/query.go b/client/go/src/cmd/query.go
index bf678b19f4d..6921cd38f89 100644
--- a/client/go/src/cmd/query.go
+++ b/client/go/src/cmd/query.go
@@ -5,7 +5,6 @@
package cmd
import (
- "bufio"
"errors"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/utils"
@@ -51,14 +50,7 @@ func query(arguments []string) {
defer response.Body.Close()
if (response.StatusCode == 200) {
- // TODO: Pretty-print body
- scanner := bufio.NewScanner(response.Body)
- for ;scanner.Scan(); {
- utils.Print(scanner.Text())
- }
- if err := scanner.Err(); err != nil {
- utils.Error(err.Error())
- }
+ utils.PrintReader(response.Body)
} else if response.StatusCode % 100 == 4 {
utils.Error("Invalid query (status ", response.Status, ")")
utils.Detail()
diff --git a/client/go/src/utils/http.go b/client/go/src/utils/http.go
index 977669a4da2..159ffb8d11a 100644
--- a/client/go/src/utils/http.go
+++ b/client/go/src/utils/http.go
@@ -53,4 +53,3 @@ func HttpDo(request *http.Request, timeout time.Duration, description string) *h
}
return response
}
-
diff --git a/client/go/src/utils/print.go b/client/go/src/utils/print.go
index f13a2c45cd0..f3a57c4ba2f 100644
--- a/client/go/src/utils/print.go
+++ b/client/go/src/utils/print.go
@@ -5,6 +5,7 @@
package utils
import (
+ "bufio"
"fmt"
"io"
"os"
@@ -37,6 +38,18 @@ func Detail(messages ...string) {
print("\033[33m", messages)
}
+// Prints all the text of the given reader
+func PrintReader(reader io.ReadCloser) {
+ // TODO: Pretty-print body
+ scanner := bufio.NewScanner(reader)
+ for ;scanner.Scan(); {
+ Print(scanner.Text())
+ }
+ if err := scanner.Err(); err != nil {
+ Error(err.Error())
+ }
+}
+
func print(prefix string, messages []string) {
fmt.Fprint(Out, prefix)
for i := 0; i < len(messages); i++ {