Skip to content

Commit

Permalink
Merge pull request #6 from alehechka/feature/read-bytes
Browse files Browse the repository at this point in the history
Add ReadBytes method to Gen
  • Loading branch information
alehechka authored Jun 26, 2022
2 parents b2ae432 + 056a9af commit 268b409
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions gen/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 7 additions & 0 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gen
import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 268b409

Please sign in to comment.