mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Fix escaping
This commit is contained in:
@@ -33,8 +33,13 @@ const (
|
||||
var (
|
||||
// jsonHandle and jsonHandlePretty are the codec handles to JSON encode
|
||||
// structs. The pretty handle will add indents for easier human consumption.
|
||||
jsonHandle = &codec.JsonHandle{}
|
||||
jsonHandlePretty = &codec.JsonHandle{Indent: 4}
|
||||
jsonHandle = &codec.JsonHandle{
|
||||
HTMLCharsAsIs: true,
|
||||
}
|
||||
jsonHandlePretty = &codec.JsonHandle{
|
||||
HTMLCharsAsIs: true,
|
||||
Indent: 4,
|
||||
}
|
||||
)
|
||||
|
||||
// HTTPServer is used to wrap an Agent and expose it over an HTTP interface
|
||||
|
||||
@@ -2,10 +2,18 @@ package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"text/template"
|
||||
|
||||
"github.com/ugorji/go/codec"
|
||||
)
|
||||
|
||||
var (
|
||||
jsonHandlePretty = &codec.JsonHandle{
|
||||
HTMLCharsAsIs: true,
|
||||
Indent: 4,
|
||||
}
|
||||
)
|
||||
|
||||
//DataFormatter is a transformer of the data.
|
||||
@@ -33,12 +41,16 @@ type JSONFormat struct {
|
||||
|
||||
// TransformData returns JSON format string data.
|
||||
func (p *JSONFormat) TransformData(data interface{}) (string, error) {
|
||||
out, err := json.MarshalIndent(&data, "", " ")
|
||||
var buf bytes.Buffer
|
||||
enc := codec.NewEncoder(&buf, jsonHandlePretty)
|
||||
err := enc.Encode(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
buf.Write([]byte("\n"))
|
||||
}
|
||||
|
||||
return string(out), nil
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
type TemplateFormat struct {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -158,12 +157,17 @@ func (c *InspectCommand) Run(args []string) int {
|
||||
|
||||
// Print the contents of the job
|
||||
req := api.RegisterJobRequest{Job: job}
|
||||
buf, err := json.MarshalIndent(req, "", " ")
|
||||
f, err := DataFormat("json", "")
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error converting job: %s", err))
|
||||
c.Ui.Error(fmt.Sprintf("Error getting formatter: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
c.Ui.Output(string(buf))
|
||||
out, err := f.TransformData(req)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error formatting the data: %s", err))
|
||||
return 1
|
||||
}
|
||||
c.Ui.Output(out)
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user