Skip to content

Commit

Permalink
wrap the JSON data structure with some metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
bjesus committed Sep 6, 2024
1 parent ee41354 commit b76f462
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion outputs/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func OutputJSON(app *common.PipetApp) string {
jsonData, _ := json.MarshalIndent(app.Data, "", " ")
jsonData, _ := json.MarshalIndent(WrapData(app.Data), "", " ")
return string(jsonData)

}
2 changes: 1 addition & 1 deletion outputs/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (
func OutputTemplate(app *common.PipetApp, templateFile string) string {
tmpl, _ := template.ParseFiles(templateFile)
var doc bytes.Buffer
tmpl.Execute(&doc, app.Data)
tmpl.Execute(&doc, WrapData(app.Data))
return doc.String()
}
12 changes: 12 additions & 0 deletions outputs/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package outputs

import "time"

func WrapData(data []interface{}) map[string]interface{} {

return map[string]interface{}{
"result": data,
"timestamp": time.Now().Format(time.RFC3339),
}

}

0 comments on commit b76f462

Please sign in to comment.