mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
Merge pull request #267 from econnell/master
agent: added URL query parameter of "pretty=true" to output formatted json
This commit is contained in:
commit
0544162f3f
@ -1,7 +1,6 @@
|
|||||||
package agent
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/hashicorp/consul/consul/structs"
|
"github.com/hashicorp/consul/consul/structs"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
@ -138,15 +137,23 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prettyPrint := false
|
||||||
|
if req.URL.Query().Get("pretty") != "" {
|
||||||
|
prettyPrint = true
|
||||||
|
}
|
||||||
// Write out the JSON object
|
// Write out the JSON object
|
||||||
if obj != nil {
|
if obj != nil {
|
||||||
var buf bytes.Buffer
|
var buf []byte
|
||||||
enc := json.NewEncoder(&buf)
|
if prettyPrint {
|
||||||
if err = enc.Encode(obj); err != nil {
|
buf, err = json.MarshalIndent(obj, "", " ")
|
||||||
|
} else {
|
||||||
|
buf, err = json.Marshal(obj)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
goto HAS_ERR
|
goto HAS_ERR
|
||||||
}
|
}
|
||||||
resp.Header().Set("Content-Type", "application/json")
|
resp.Header().Set("Content-Type", "application/json")
|
||||||
resp.Write(buf.Bytes())
|
resp.Write(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return f
|
return f
|
||||||
|
@ -79,6 +79,12 @@ which is the last time a server was contacted by the leader node in
|
|||||||
milliseconds. The "X-Consul-KnownLeader" also indicates if there is a known
|
milliseconds. The "X-Consul-KnownLeader" also indicates if there is a known
|
||||||
leader. These can be used to gauge if a stale read should be used.
|
leader. These can be used to gauge if a stale read should be used.
|
||||||
|
|
||||||
|
## Formatted JSON Output
|
||||||
|
|
||||||
|
By default, the output of all HTTP API requests return minimized JSON with all
|
||||||
|
whitespace removed. By adding "?pretty=true" to the HTTP request URL,
|
||||||
|
formatted JSON will be returned.
|
||||||
|
|
||||||
## KV
|
## KV
|
||||||
|
|
||||||
The KV endpoint is used to expose a simple key/value store. This can be used
|
The KV endpoint is used to expose a simple key/value store. This can be used
|
||||||
|
Loading…
x
Reference in New Issue
Block a user