Documentation ¶
Index ¶
- Variables
- type DefaultFieldNamer
- type FieldNamer
- type Generator
- func (g *Generator) Add(obj interface{})
- func (g *Generator) DisallowUnknownFields()
- func (g *Generator) GenTypeEncoder(t reflect.Type, in string, tags fieldTags, indent int, assumeNonEmpty bool) error
- func (g *Generator) NoStdMarshalers()
- func (g *Generator) OmitEmpty()
- func (g *Generator) Run(out io.Writer) error
- func (g *Generator) SetBuildTags(tags string)
- func (g *Generator) SetFieldNamer(n FieldNamer)
- func (g *Generator) SetPkg(name, path string)
- func (g *Generator) UseLowerCamelCase()
- func (g *Generator) UseSnakeCase()
- type LowerCamelCaseFieldNamer
- type SnakeCaseFieldNamer
Constants ¶
This section is empty.
Variables ¶
var PrimitiveEncoders = map[reflect.Kind]string{ reflect.String: "out.String(string(%v))", reflect.Bool: "out.Bool(bool(%v))", reflect.Int: "out.Int(int(%v))", reflect.Int8: "out.Int8(int8(%v))", reflect.Int16: "out.Int16(int16(%v))", reflect.Int32: "out.Int32(int32(%v))", reflect.Int64: "out.Int64(int64(%v))", reflect.Uint: "out.Uint(uint(%v))", reflect.Uint8: "out.Uint8(uint8(%v))", reflect.Uint16: "out.Uint16(uint16(%v))", reflect.Uint32: "out.Uint32(uint32(%v))", reflect.Uint64: "out.Uint64(uint64(%v))", reflect.Float32: "out.Float32(float32(%v))", reflect.Float64: "out.Float64(float64(%v))", }
var PrimitiveStringEncoders = map[reflect.Kind]string{ reflect.String: "out.String(string(%v))", reflect.Int: "out.IntStr(int(%v))", reflect.Int8: "out.Int8Str(int8(%v))", reflect.Int16: "out.Int16Str(int16(%v))", reflect.Int32: "out.Int32Str(int32(%v))", reflect.Int64: "out.Int64Str(int64(%v))", reflect.Uint: "out.UintStr(uint(%v))", reflect.Uint8: "out.Uint8Str(uint8(%v))", reflect.Uint16: "out.Uint16Str(uint16(%v))", reflect.Uint32: "out.Uint32Str(uint32(%v))", reflect.Uint64: "out.Uint64Str(uint64(%v))", reflect.Uintptr: "out.UintptrStr(uintptr(%v))", reflect.Float32: "out.Float32Str(float32(%v))", reflect.Float64: "out.Float64Str(float64(%v))", }
Functions ¶
This section is empty.
Types ¶
type DefaultFieldNamer ¶
type DefaultFieldNamer struct{}
DefaultFieldsNamer implements trivial naming policy equivalent to encoding/json.
func (DefaultFieldNamer) GetJSONFieldName ¶
func (DefaultFieldNamer) GetJSONFieldName(t reflect.Type, f reflect.StructField) string
type FieldNamer ¶
type FieldNamer interface {
GetJSONFieldName(t reflect.Type, f reflect.StructField) string
}
FieldNamer defines a policy for generating names for struct fields.
type Generator ¶
Generator generates the requested marshaler/unmarshalers.
func NewGenerator ¶
NewGenerator initializes and returns a Generator.
func (*Generator) Add ¶
func (g *Generator) Add(obj interface{})
Add requests to generate marshaler/unmarshalers and encoding/decoding funcs for the type of given object.
func (*Generator) DisallowUnknownFields ¶
func (g *Generator) DisallowUnknownFields()
DisallowUnknownFields instructs not to skip unknown fields in json and return error.
func (*Generator) GenTypeEncoder ¶
func (g *Generator) GenTypeEncoder(t reflect.Type, in string, tags fieldTags, indent int, assumeNonEmpty bool) error
genTypeEncoder generates code that encodes in of type t into the writer, but uses marshaler interface if implemented by t.
func (*Generator) NoStdMarshalers ¶
func (g *Generator) NoStdMarshalers()
NoStdMarshalers instructs not to generate standard MarshalJSON/UnmarshalJSON methods (only the custom interface).
func (*Generator) OmitEmpty ¶
func (g *Generator) OmitEmpty()
OmitEmpty triggers `json=",omitempty"` behaviour by default.
func (*Generator) SetBuildTags ¶
SetBuildTags sets build tags for the output file.
func (*Generator) SetFieldNamer ¶
func (g *Generator) SetFieldNamer(n FieldNamer)
SetFieldNamer sets field naming strategy.
func (*Generator) UseLowerCamelCase ¶
func (g *Generator) UseLowerCamelCase()
UseLowerCamelCase sets lowerCamelCase field naming strategy.
func (*Generator) UseSnakeCase ¶
func (g *Generator) UseSnakeCase()
UseSnakeCase sets snake_case field naming strategy.
type LowerCamelCaseFieldNamer ¶
type LowerCamelCaseFieldNamer struct{}
LowerCamelCaseFieldNamer
func (LowerCamelCaseFieldNamer) GetJSONFieldName ¶
func (LowerCamelCaseFieldNamer) GetJSONFieldName(t reflect.Type, f reflect.StructField) string
type SnakeCaseFieldNamer ¶
type SnakeCaseFieldNamer struct{}
SnakeCaseFieldNamer implements CamelCase to snake_case conversion for fields names.
func (SnakeCaseFieldNamer) GetJSONFieldName ¶
func (SnakeCaseFieldNamer) GetJSONFieldName(t reflect.Type, f reflect.StructField) string