Skip to content

Commit

Permalink
Merge pull request #1782 from weaveworks/1709-json-func
Browse files Browse the repository at this point in the history
Add a 'json' function for 'weave report -f'
  • Loading branch information
awh committed Dec 15, 2015
2 parents c973808 + c341399 commit 0c077b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion prog/weaver/http.go
Expand Up @@ -246,7 +246,13 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout

muxRouter.Methods("GET").Path("/report").Queries("format", "{format}").HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
formatTemplate, err := template.New("format").Parse(mux.Vars(r)["format"])
funcs := template.FuncMap{
"json": func(v interface{}) string {
a, _ := json.Marshal(v)
return string(a)
},
}
formatTemplate, err := template.New("format").Funcs(funcs).Parse(mux.Vars(r)["format"])
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
Expand Down
6 changes: 6 additions & 0 deletions site/troubleshooting.md
Expand Up @@ -232,6 +232,12 @@ inspect`:
$ weave report -f {% raw %}'{{.DNS.Domain}}'{% endraw %}
weave.local.

Weave adds a template function, `json`, which can be applied to get
results in JSON format.

$ weave report -f {% raw %}'{{json .DNS}}'{% endraw %}
{% raw %}{"Domain":"weave.local.","Upstream":["8.8.8.8","8.8.4.4"],"Address":"172.17.0.1:53","TTL":1,"Entries":null}{% endraw %}

### <a name="list-attached-containers"></a>List attached containers

weave ps
Expand Down

0 comments on commit 0c077b8

Please sign in to comment.