Documentation ¶
Index ¶
- Constants
- func CanUnmarshal(t types.Type) bool
- func IsGeneratedByNJSON(f *ast.File) bool
- func ParseFieldTag(tag, key string) (name string, omitempty, ok bool)
- type Generator
- func (g *Generator) AllStructs() (all []string)
- func (o *Generator) AppendMethod() string
- func (g *Generator) Appender(typName string) (c meta.Code)
- func (g *Generator) BasicUnmarshaler(t types.Type, b *types.Basic) (code meta.Code)
- func (g *Generator) DumpTo(w io.Writer) error
- func (g *Generator) DurationUnmarshaler(t types.Type) (code meta.Code)
- func (g *Generator) EnsurePath(path meta.FieldPath) (code meta.Code)
- func (g *Generator) EnsureReversePath(path meta.FieldPath, code meta.Code) meta.Code
- func (g *Generator) Filename() (name string)
- func (g *Generator) Header() string
- func (g *Generator) Import(imports ...*types.Package)
- func (g *Generator) InterfaceUnmarshaler(t types.Type, b *types.Interface) (code meta.Code)
- func (o *Generator) JSONFieldName(name string) string
- func (g *Generator) JSONUnmarshaler(t types.Type) (code meta.Code)
- func (g *Generator) MapUnmarshaler(t types.Type, m *types.Map) (code meta.Code)
- func (o *Generator) MatchField(name string) bool
- func (g *Generator) NodeJSONUnmarshaler(t types.Type) (code meta.Code)
- func (g *Generator) OmiterType() (string, *types.Interface)
- func (g *Generator) PointerUnmarshaler(T types.Type, t *types.Pointer) (code meta.Code)
- func (g *Generator) PrintTo(w io.Writer) error
- func (g *Generator) RawStringUnmarshaler(t types.Type) meta.Code
- func (g *Generator) Reset()
- func (g *Generator) SliceUnmarshaler(T types.Type, t *types.Slice) meta.Code
- func (g *Generator) StructAppender(fields meta.Fields) (c meta.Code)
- func (g *Generator) StructUnmarshaler(t *types.Struct) (code meta.Code)
- func (o *Generator) TagKey() string
- func (g *Generator) TextUnmarshaler(t types.Type) (code meta.Code)
- func (g *Generator) TimeUnmarshaler(t types.Type) (code meta.Code)
- func (g *Generator) TypeAppender(typ types.Type, params meta.Params) (c meta.Code)
- func (g *Generator) TypeOmiter(typ types.Type, block meta.Code) meta.Code
- func (g *Generator) TypeUnmarshaler(t types.Type) (code meta.Code)
- func (o *Generator) UnmarshalMethod() string
- func (g *Generator) Unmarshaler(typeName string) (code meta.Code)
- func (g *Generator) WriteAppender(typName string) (err error)
- func (g *Generator) WriteUnmarshaler(typeName string) (err error)
- type Option
- func AppendMethod(methodName string) Option
- func ForceOmitEmpty(on bool) Option
- func Logger(logger *log.Logger) Option
- func MatchFieldName(rx *regexp.Regexp) Option
- func OmitMethod(methodName string) Option
- func OnlyExported(on bool) Option
- func OnlyTagged(on bool) Option
- func TagKey(key string) Option
- func TransformFieldCase(mode string) Option
- func UnmarshalMethod(methodName string) Option
Constants ¶
const DefaultTagKey = "json"
DefaultTagKey is the default tag key to use when parsing stuct fields.
Variables ¶
This section is empty.
Functions ¶
func IsGeneratedByNJSON ¶
IsGeneratedByNJSON checks if a file begins with the njson generated header comment.
func ParseFieldTag ¶
ParseFieldTag parses a field tag to get a json name and omitempty info.
Types ¶
type Generator ¶
Generator is a source code generator for njson unmarshal methods.
func NewFromDir ¶
NewFromDir creates a new Generator for a package named targetPkg and parses the specified path.
func NewFromFile ¶
NewFromFile creates a new Generator for a package named targetPkg and parses the specified file.
func (*Generator) AllStructs ¶
AllStructs returns all structs from the package.
func (*Generator) AppendMethod ¶
func (o *Generator) AppendMethod() string
func (*Generator) BasicUnmarshaler ¶
BasicUnmarshaler generates the code block to unmarshal a basic type.
func (*Generator) DurationUnmarshaler ¶
DurationUnmarshaler generates code to unmarshal time.Time values.
func (*Generator) EnsurePath ¶
EnsurePath generates a code block to ensure the path to an embedded pointer to struct has no nils.
func (*Generator) EnsureReversePath ¶
EnsureReversePath returns a code block to check the path to an embedded field does not contain any nil pointers
func (*Generator) InterfaceUnmarshaler ¶
InterfaceUnmarshaler generates the code block to unmarshal an empty interface.
func (*Generator) JSONFieldName ¶
func (*Generator) JSONUnmarshaler ¶
JSONUnmarshaler generates code to wrap the UnmarshalJSON method of a value.
func (*Generator) MapUnmarshaler ¶
MapUnmarshaler generates the code block to unmarshal a map.
func (*Generator) MatchField ¶
func (*Generator) NodeJSONUnmarshaler ¶
NodeJSONUnmarshaler generates code to wrap the UnmarshalNodeJSON method of a value.
func (*Generator) OmiterType ¶
OmiterType returns the interface for an omiter
func (*Generator) PointerUnmarshaler ¶
PointerUnmarshaler generates the code block to unmarshal a pointer type.
func (*Generator) RawStringUnmarshaler ¶
RawStringUnmarshaler unmarshals strings without unescaping
func (*Generator) Reset ¶
func (g *Generator) Reset()
Reset resets the generator to start a new file.
func (*Generator) SliceUnmarshaler ¶
SliceUnmarshaler generates the code block to unmarshal a slice.
func (*Generator) StructAppender ¶
StructAppender returns the AppendJSON block code for a struct
func (*Generator) StructUnmarshaler ¶
StructUnmarshaler generates the code block to unmarshal a struct.
func (*Generator) TextUnmarshaler ¶
TextUnmarshaler generates code to wrap the UnmarshalText method of a value.
func (*Generator) TimeUnmarshaler ¶
TimeUnmarshaler generates code to unmarshal time.Time values.
func (*Generator) TypeAppender ¶
TypeAppender returnds the AppendJSON block code for a type
func (*Generator) TypeOmiter ¶
TypeOmiter returns the code block to check if a value should be omitted
func (*Generator) TypeUnmarshaler ¶
TypeUnmarshaler returns the code block for unmarshaling a type.
func (*Generator) UnmarshalMethod ¶
func (o *Generator) UnmarshalMethod() string
func (*Generator) Unmarshaler ¶
Unmarshaler generates an unmarshaler method for a type
func (*Generator) WriteAppender ¶
WriteAppender writes an AppendJSON method for a type
func (*Generator) WriteUnmarshaler ¶
WriteUnmarshaler writes an unmarshaler method for a type in the generator's buffer.
type Option ¶
type Option func(g *Generator)
Option is a generator option
func AppendMethod ¶
AppendMethod sets the tag key to use when parsing struct fields
func ForceOmitEmpty ¶
ForceOmitEmpty forces omitempty on all fields regardless of json tag.
func MatchFieldName ¶
MatchFieldName sets a regex for matching struct field names
func OmitMethod ¶
OmitMethod sets the tag key to use when parsing struct fields
func OnlyExported ¶
OnlyExported forces generator to ignore unexported fields
func OnlyTagged ¶
OnlyTagged forces generator to ignore fields without a tag
func TransformFieldCase ¶
TransformFieldCase sets a case transformation mode for field names when no tag based name is found.
func UnmarshalMethod ¶
UnmarshalMethod sets the tag key to use when parsing struct fields