Documentation ¶
Index ¶
- Variables
- func GetFileGoName(filePath string) string
- func GetGoName(input string) string
- type Field
- func (f Field) Comment() string
- func (f Field) Equals(input *Field) bool
- func (f Field) GetSliceStruct() *JSONStruct
- func (f Field) GetStruct() *JSONStruct
- func (f Field) IsSlice() bool
- func (f Field) IsStruct() bool
- func (f Field) IsStructSlice() bool
- func (f Field) Name() string
- func (f Field) OriginalName() string
- func (f *Field) SetJSONRaw() *Field
- func (f *Field) SetName(originalName string) *Field
- func (f *Field) SetOptional() *Field
- func (f *Field) SetValue(value any) *Field
- func (f Field) SimpleSliceValues() []string
- func (f Field) SliceType() string
- func (f Field) Tag() string
- func (f Field) Type() string
- func (f Field) Value() string
- type Fields
- type Formatter
- type FormatterOptions
- type JSONStruct
- func (j *JSONStruct) AddFields(fields ...*Field) *JSONStruct
- func (j *JSONStruct) Fields() Fields
- func (j *JSONStruct) Name() string
- func (j *JSONStruct) NestLevel() int
- func (j *JSONStruct) SetInSlice() *JSONStruct
- func (j *JSONStruct) SetName(name string) *JSONStruct
- func (j *JSONStruct) SetNestLevel(i int) *JSONStruct
- type JSONStructs
- type Parser
Constants ¶
This section is empty.
Variables ¶
var CommonInitialisms = map[string]bool{ "ACL": true, "API": true, "ASCII": true, "CPU": true, "CSS": true, "DNS": true, "EOF": true, "GUID": true, "HTML": true, "HTTP": true, "HTTPS": true, "ID": true, "IP": true, "JSON": true, "LHS": true, "QPS": true, "RAM": true, "RHS": true, "RPC": true, "SLA": true, "SMTP": true, "SQL": true, "SSH": true, "TCP": true, "TLS": true, "TTL": true, "UDP": true, "UI": true, "UID": true, "UUID": true, "URI": true, "URL": true, "UTF8": true, "VM": true, "XML": true, "XMPP": true, "XSRF": true, "XSS": true, }
CommonInitialisms contains the words that are recognized by "go lint" as initials needing capitalization.
var ErrOverflow = errors.New("provided number was too large")
Functions ¶
func GetFileGoName ¶
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field represents a single struct field.
func (Field) Equals ¶
Equals returns true if two Fields share an original name, Go name, and type - does not compare values!
func (Field) GetSliceStruct ¶
func (f Field) GetSliceStruct() *JSONStruct
func (Field) GetStruct ¶
func (f Field) GetStruct() *JSONStruct
GetStruct gets a the JSONStruct in RawValue if f is a struct or slice of struct, otherwise returns nil.
func (Field) IsStruct ¶
IsStruct returns true if RawValue is either a struct or a pointer to a struct.
func (Field) IsStructSlice ¶
func (Field) OriginalName ¶
func (*Field) SetJSONRaw ¶
func (*Field) SetOptional ¶
func (Field) SimpleSliceValues ¶
SimpleSliceValues returns a slice of strings with the values of simple slice Fields ([]int64, []float64, []bool, []string). If it doesn't recognize the Field as one of these, it returns an empty slice.
type Fields ¶
type Fields []*Field
Fields is a convenience type for a slice of Field structs.
func (Fields) SortAlphabetically ¶
func (f Fields) SortAlphabetically()
type Formatter ¶
type Formatter struct {
*FormatterOptions
}
Formatter prints out the contents of JSONStructs based on its configuration.
func NewFormatter ¶
func NewFormatter(opts *FormatterOptions) (*Formatter, error)
NewFormatter returns an initialized Formatter.
func (*Formatter) FormatStructs ¶
func (f *Formatter) FormatStructs(inputs ...*JSONStruct) (string, error)
type FormatterOptions ¶
type FormatterOptions struct { // SortFields returns fields in alphabetically sorted order. SortFields bool // ValueComments annotates the produced structs with "Example" comments including the values originally passed in // for this field. ValueComments bool // InlineStructs causes objects within the main object to be rendered inline rather than getting their own types. InlineStructs bool }
FormatterOptions defines how the Formatter will produce its output.
func (*FormatterOptions) OK ¶
func (f *FormatterOptions) OK() error
OK ensures that the options passed in are valid.
type JSONStruct ¶
type JSONStruct struct {
// contains filtered or unexported fields
}
JSONStruct contains the raw information about a JSON object to be rendered as a Go struct.
func (*JSONStruct) AddFields ¶
func (j *JSONStruct) AddFields(fields ...*Field) *JSONStruct
AddFields appends Field objects to the JSONStruct.
func (*JSONStruct) Fields ¶
func (j *JSONStruct) Fields() Fields
func (*JSONStruct) Name ¶
func (j *JSONStruct) Name() string
func (*JSONStruct) NestLevel ¶
func (j *JSONStruct) NestLevel() int
func (*JSONStruct) SetInSlice ¶
func (j *JSONStruct) SetInSlice() *JSONStruct
func (*JSONStruct) SetName ¶
func (j *JSONStruct) SetName(name string) *JSONStruct
SetName sets the name to be used as a type for the JSONStruct.
func (*JSONStruct) SetNestLevel ¶
func (j *JSONStruct) SetNestLevel(i int) *JSONStruct
AddInlineLevels recursively sets the inlineLevel value for this JSONStruct, as well as its struct fields.
type JSONStructs ¶
type JSONStructs []*JSONStruct
JSONStructs is a convenience type for a slice of JSONStruct structs.