Documentation ¶
Index ¶
- Variables
- func SplitComponents(name string) []string
- type AbbreviationHandlingFieldNamer
- type FieldNamer
- type Generator
- type GeneratorOption
- func WithAddStructTagName(structTagName string) GeneratorOption
- func WithFieldNamer(fieldNamer FieldNamer) GeneratorOption
- func WithGoFormat(goFormat bool) GeneratorOption
- func WithImports(imports ...string) GeneratorOption
- func WithIntType(intType string) GeneratorOption
- func WithOmitEmpty(omitEmptyOption OmitEmptyOption) GeneratorOption
- func WithPackageComment(packageComment string) GeneratorOption
- func WithPackageName(packageName string) GeneratorOption
- func WithSkipUnparseableProperties(skipUnparseableProperties bool) GeneratorOption
- func WithStructTagName(structTagName string) GeneratorOption
- func WithStructTagNames(structTagNames []string) GeneratorOption
- func WithTypeComment(typeComment string) GeneratorOption
- func WithTypeName(typeName string) GeneratorOption
- func WithUseInline(useInline bool) GeneratorOption
- func WithUseJSONNumber(useJSONNumber bool) GeneratorOption
- type ObservedValue
- type OmitEmptyOption
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func SplitComponents ¶
SplitComponents splits name into components. name may be kebab case, snake case, or camel case.
Types ¶
type AbbreviationHandlingFieldNamer ¶
An AbbreviationHandlingFieldNamer generates Go field names from JSON properties while keeping abbreviations uppercased.
func (*AbbreviationHandlingFieldNamer) FieldName ¶
func (a *AbbreviationHandlingFieldNamer) FieldName(property string) string
FieldName implements FieldNamer.FieldName.
type FieldNamer ¶
A FieldNamer generates a Go field name from a JSON property.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
A Generator generates Go types from ObservedValues.
func NewGenerator ¶
func NewGenerator(options ...GeneratorOption) *Generator
NewGenerator returns a new Generator with options.
type GeneratorOption ¶
type GeneratorOption func(*Generator)
A GeneratorOption sets an option on a Generator.
func WithAddStructTagName ¶
func WithAddStructTagName(structTagName string) GeneratorOption
WithAddStructTagName adds a struct tag name.
func WithFieldNamer ¶
func WithFieldNamer(fieldNamer FieldNamer) GeneratorOption
WithFieldNamer sets the fieldNamer.
func WithGoFormat ¶
func WithGoFormat(goFormat bool) GeneratorOption
WithGoFormat sets whether the output is should be formatted with go fmt.
func WithImports ¶
func WithImports(imports ...string) GeneratorOption
WithImports adds custom package imports.
func WithIntType ¶
func WithIntType(intType string) GeneratorOption
WithIntType sets the integer type.
func WithOmitEmpty ¶
func WithOmitEmpty(omitEmptyOption OmitEmptyOption) GeneratorOption
WithOmitEmpty sets whether each field is tagged with omitempty.
func WithPackageComment ¶
func WithPackageComment(packageComment string) GeneratorOption
WithPackageComment sets the package comment.
func WithPackageName ¶
func WithPackageName(packageName string) GeneratorOption
WithPackageName sets the package name.
func WithSkipUnparseableProperties ¶
func WithSkipUnparseableProperties(skipUnparseableProperties bool) GeneratorOption
WithSkipUnparseableProperties sets whether unparseable properties should be skipped.
func WithStructTagName ¶
func WithStructTagName(structTagName string) GeneratorOption
WithStructTagName sets the struct tag name.
func WithStructTagNames ¶
func WithStructTagNames(structTagNames []string) GeneratorOption
WithStructTagNames sets the struct tag names.
func WithTypeComment ¶
func WithTypeComment(typeComment string) GeneratorOption
WithTypeComment sets the type comment.
func WithTypeName ¶
func WithTypeName(typeName string) GeneratorOption
WithTypeName sets the type name.
func WithUseInline ¶
func WithUseInline(useInline bool) GeneratorOption
WithUseInline sets whether to output structs should be inline
func WithUseJSONNumber ¶
func WithUseJSONNumber(useJSONNumber bool) GeneratorOption
WithUseJSONNumber sets whether to use json.Number when both int and float64s are observed for the same property.
type ObservedValue ¶
type ObservedValue struct { Observations int Empty int Array int Bool int Float64 int Int int Null int Object int String int Time int // time.Time is an implicit more specific type than string. AllArrayElementValues *ObservedValue AllObjectPropertyValues *ObservedValue ObjectPropertyValue map[string]*ObservedValue FieldKey string }
An ObservedValue is an observed value.
func ObserveJSON ¶
func ObserveJSON(r io.Reader) (*ObservedValue, error)
ObserveJSON returns all JSON values observed in r.
func ObserveYAML ¶
func ObserveYAML(r io.Reader) (*ObservedValue, error)
ObserveYAML returns all YAML values observed in r.
func (*ObservedValue) Merge ¶
func (o *ObservedValue) Merge(value interface{}) *ObservedValue
Merge merges value into o.
type OmitEmptyOption ¶
type OmitEmptyOption int
An OmitEmptyOption is an option for handling omitempty.
const ( OmitEmptyNever OmitEmptyOption = iota OmitEmptyAlways OmitEmptyAuto )
omitempty options.