gout
is the Go OUTput Formatter for serializing data in a standard way.
Helper utility to output data structures in to standardized formats, much like what is built in to vault, az and kubectl
I really like how these apps provide for flexible output, but wanted a way to do it without needing to re-write or copy it for every new tool.
Need to parse some output with jq
? JSON is your format. Want to put
it out in an easy to read yet still standardized format? YAML is for you!
This tool is intended to provide all that in a single reusable package.
import "github.com/drewstinnett/gout/v2"
Gout now comes with a builtin instance, similar to the way Viper does things.
Example Usage:
gout.MustPrint(struct {
FirstName string
LastName string
}{
FirstName: "Bob",
LastName: "Ross",
})
Full example code here
Example Usage:
// Create a new instance
w, err := gout.New()
if err != nil {
panic(err)
}
// Use a custom writer
w.SetWriter(os.Stderr)
// Print something!
w.MustPrint(struct {
FirstName string
LastName string
}{
FirstName: "Bob",
LastName: "Ross",
})
// {"FirstName":"Bob","LastName":"Ross"}
Uses the standard gopkg.in/yaml.v3
library.
Uses the standard encoding/json
library.
Uses github.com/pelletier/go-toml/v2
library
Uses github.com/jszwec/csvutil
library. NOTE: You must pass an iterable
interface in when using this format. It won't do a single struct.
Uses encoding/xml
library. NOTE: This plugin only works with structs supported
by the base library
This is just vanilla old Golang output, using the %+v
format.
Use this format to parse the data in to a golang template. Useful for spitting
data out in a more arbitrary format. This uses the text/template
package to
parse each item in the return slice. See the example
here for full details.
- Gout-Cobra - Configure a cobra.Command to output using Gout
Intention here is to have a simple way to print out a data structure in a way that grep and the like can parse it.