diff --git a/cmd/generate.go b/cmd/generate.go index 001c2ef..81f1353 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -34,7 +34,7 @@ var generateFlags = []cli.Flag{ Name: rootFlag, Aliases: []string{"r"}, Usage: "The name of the root object or array", - Value: "Root", + Value: gen.DefaultRootName, }, &cli.StringFlag{ Name: packageFlag, diff --git a/gen/constants.go b/gen/constants.go index e38dc29..b84a40f 100644 --- a/gen/constants.go +++ b/gen/constants.go @@ -5,3 +5,6 @@ const DefaultOutputFile = "types.go" // DefaultPackage is the name of the default package const DefaultPackage = "main" + +// DefaultRootName is the default name of the top-level JSON object +const DefaultRootName = "Root" diff --git a/gen/gen.go b/gen/gen.go index fbe5097..5315782 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -3,6 +3,7 @@ package gen import ( "encoding/json" "errors" + "io" "io/ioutil" "log" "os" @@ -69,6 +70,12 @@ func (g *Gen) SetBytes(bytes []byte) *Gen { return g } +// ReadBytes allows for the explicit setting of raw bytes via io.Reader +func (g *Gen) ReadBytes(r io.Reader) *Gen { + g.bytes, _ = ioutil.ReadAll(r) + return g +} + // SetJSON allows for the explicit setting of provided JSON payload // TODO: Needs further testing before ready for external usage. func (g *Gen) setJSON(json interface{}) *Gen {