Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ShortWriteError ¶
type ShortWriteError struct {
// contains filtered or unexported fields
}
func (ShortWriteError) Error ¶
func (e ShortWriteError) Error() string
type Transmogrifier ¶
type Transmogrifier struct { // ImportJSON is used to control whether or not an import statement // for encoding/json should be generated. ImportJSON bool // WriteJSON is used to control whether or not the source JSON // should be written. The JSON will be written using MarshalIndent // with '\t', tab, as the indent. This only applies when the output // destination is not stdout. WriteJSON bool // MapType is used for JSON data that is map[string]interface{}, // map[string][]interface{}, or a slice of either of the two. If // true, instead of generating a struct definition for the type, the // type will be either map[string]T or map[string][]T. When the // created type is a map, the name of the struct T should be set // using SetStructName. If it isn't set, T will be named Struct. // // If false, a struct definition will be generated for the type. MapType bool // StringTag is used to guess whether a string type field can // be parsed as a Int/Float value. And a `,string“ tag will be // added to the tail of the tag of that field. StringTag bool // contains filtered or unexported fields }
Transmogrifier turns JSON into Go struct definitions.
func NewTransmogrifier ¶
NewTransmogrifier returns a new transmogrifier that reads from r and writes to w. The name is the name of the type that will be defined from the JSON. Embedded struct names, if there are any embedded structs, are derived from their associated key value.
func (*Transmogrifier) Gen ¶
func (t *Transmogrifier) Gen() error
Gen generates the struct definitions and outputs it to W.
func (*Transmogrifier) SetJSONWriter ¶
func (t *Transmogrifier) SetJSONWriter(w io.Writer)
SetJSONWriter set's the writer to which the original json is written to, This is most useful when getting the JSON from stdin.
func (*Transmogrifier) SetPkg ¶
func (t *Transmogrifier) SetPkg(s string)
SetPkg set's the package name to s. The package name will be lowercased.
func (*Transmogrifier) SetStructName ¶
func (t *Transmogrifier) SetStructName(s string)
SetStructName sets the name of the type derived from the interface{} portion of JSON that is of type map[string]interface{}. This is used when MapType is set to true. If MapType is set to true but typeName is not set, Struct will be used as the type name.
func (*Transmogrifier) SetTagKeys ¶
func (t *Transmogrifier) SetTagKeys(v []string) error
SetTagKeys set's the additional keys that should be added to struct tags. This list should not include `json` as the `json` tag key is always defined for each field.