diff --git a/prog/weaver/http.go b/prog/weaver/http.go index a0cca5c88d..c02b2bdb6d 100644 --- a/prog/weaver/http.go +++ b/prog/weaver/http.go @@ -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 diff --git a/site/troubleshooting.md b/site/troubleshooting.md index 22b81758e0..30d5919eaf 100644 --- a/site/troubleshooting.md +++ b/site/troubleshooting.md @@ -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 %} + ### List attached containers weave ps