Documentation ¶
Overview ¶
Package jawn - Zero allocation Nullable structures in one library with handy conversion functions, marshallers and unmarshallers.
Features: - short name "jawn" - handy conversion functions - select which marshalers you want and limit dependencies to only those you actually need
Supported types: - bool - float32 - float64 - int - int8 - int16 - int32 - int64 - string - time.Time - more types will be added at necessary
Supported marshallers: - Standart JSON - jsoniter - easyjson - Scylla and Cassandra. Compatible with gocql - SQL
Usage ¶
Simply create struct field or variable with one of the exported types and use it without any changes to external API.
JSON input/output will be converted to null or non null values. Scylla and Cassandra will use wire format compatible with gocql.
var data struct { Code jawn.NullString `json:"code"` } b, err := jsoniter.Marshal(data) if err != nil { panic(err) } // {"code":null} fmt.Println(string(b)) data.Code = jawn.String("1") // Or // data.Code = jawn.NullString{String: "1", Valid: true} b, err = jsoniter.Marshal(data) if err != nil { panic(err) } // {"code":"1"} fmt.Println(string(b))
Index ¶
- type Mashaler
- type NullBool
- func (n NullBool) IsDefined() bool
- func (n NullBool) IsValid() bool
- func (n NullBool) IsZero() bool
- func (n NullBool) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullBool) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullBool) MarshalJSON() ([]byte, error)
- func (n *NullBool) Scan(value interface{}) error
- func (n *NullBool) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullBool) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullBool) UnmarshalJSON(data []byte) error
- func (n NullBool) Value() (driver.Value, error)
- type NullDuration
- func (n NullDuration) IsDefined() bool
- func (n NullDuration) IsValid() bool
- func (n NullDuration) IsZero() bool
- func (n NullDuration) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullDuration) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullDuration) MarshalJSON() ([]byte, error)
- func (n *NullDuration) Scan(value interface{}) error
- func (n *NullDuration) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullDuration) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullDuration) UnmarshalJSON(data []byte) error
- func (n NullDuration) Value() (driver.Value, error)
- type NullFloat32
- func (n NullFloat32) IsDefined() bool
- func (n NullFloat32) IsValid() bool
- func (n NullFloat32) IsZero() bool
- func (n NullFloat32) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullFloat32) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullFloat32) MarshalJSON() ([]byte, error)
- func (n *NullFloat32) Scan(value interface{}) error
- func (n *NullFloat32) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullFloat32) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullFloat32) UnmarshalJSON(data []byte) error
- func (n NullFloat32) Value() (driver.Value, error)
- type NullFloat64
- func (n NullFloat64) IsDefined() bool
- func (n NullFloat64) IsValid() bool
- func (n NullFloat64) IsZero() bool
- func (n NullFloat64) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullFloat64) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullFloat64) MarshalJSON() ([]byte, error)
- func (n *NullFloat64) Scan(value interface{}) error
- func (n *NullFloat64) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullFloat64) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullFloat64) UnmarshalJSON(data []byte) error
- func (n NullFloat64) Value() (driver.Value, error)
- type NullInt
- func (n NullInt) IsDefined() bool
- func (n NullInt) IsValid() bool
- func (n NullInt) IsZero() bool
- func (n NullInt) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullInt) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullInt) MarshalJSON() ([]byte, error)
- func (n *NullInt) Scan(value interface{}) error
- func (n *NullInt) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullInt) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullInt) UnmarshalJSON(data []byte) error
- func (n NullInt) Value() (driver.Value, error)
- type NullInt16
- func (n NullInt16) IsDefined() bool
- func (n NullInt16) IsValid() bool
- func (n NullInt16) IsZero() bool
- func (n NullInt16) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullInt16) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullInt16) MarshalJSON() ([]byte, error)
- func (n *NullInt16) Scan(value interface{}) error
- func (n *NullInt16) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullInt16) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullInt16) UnmarshalJSON(data []byte) error
- func (n NullInt16) Value() (driver.Value, error)
- type NullInt32
- func (n NullInt32) IsDefined() bool
- func (n NullInt32) IsValid() bool
- func (n NullInt32) IsZero() bool
- func (n NullInt32) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullInt32) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullInt32) MarshalJSON() ([]byte, error)
- func (n *NullInt32) Scan(value interface{}) error
- func (n *NullInt32) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullInt32) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullInt32) UnmarshalJSON(data []byte) error
- func (n NullInt32) Value() (driver.Value, error)
- type NullInt64
- func (n NullInt64) IsDefined() bool
- func (n NullInt64) IsValid() bool
- func (n NullInt64) IsZero() bool
- func (n NullInt64) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullInt64) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullInt64) MarshalJSON() ([]byte, error)
- func (n *NullInt64) Scan(value interface{}) error
- func (n *NullInt64) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullInt64) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullInt64) UnmarshalJSON(data []byte) error
- func (n NullInt64) Value() (driver.Value, error)
- type NullInt8
- func (n NullInt8) IsDefined() bool
- func (n NullInt8) IsValid() bool
- func (n NullInt8) IsZero() bool
- func (n NullInt8) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullInt8) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullInt8) MarshalJSON() ([]byte, error)
- func (n *NullInt8) Scan(value interface{}) error
- func (n *NullInt8) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullInt8) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullInt8) UnmarshalJSON(data []byte) error
- func (n NullInt8) Value() (driver.Value, error)
- type NullString
- func (n NullString) IsDefined() bool
- func (n NullString) IsValid() bool
- func (n NullString) IsZero() bool
- func (n NullString) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullString) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullString) MarshalJSON() ([]byte, error)
- func (ns *NullString) Scan(value interface{}) error
- func (n *NullString) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullString) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullString) UnmarshalJSON(data []byte) error
- func (ns NullString) Value() (driver.Value, error)
- type NullTime
- func (n NullTime) IsDefined() bool
- func (n NullTime) IsValid() bool
- func (n NullTime) IsZero() bool
- func (n NullTime) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (n NullTime) MarshalEasyJSON(out *jwriter.Writer)
- func (n NullTime) MarshalJSON() ([]byte, error)
- func (n *NullTime) Scan(value interface{}) error
- func (n *NullTime) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
- func (n *NullTime) UnmarshalEasyJSON(in *jlexer.Lexer)
- func (n *NullTime) UnmarshalJSON(data []byte) error
- func (n NullTime) Value() (driver.Value, error)
- type Validator
- type Zeroer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NullBool ¶
NullBool - nullable bool
func BoolToNullBool
deprecated
func (NullBool) MarshalBSONValue ¶
func (NullBool) MarshalEasyJSON ¶
MarshalEasyJSON - marshaller for easyjson
func (NullBool) MarshalJSON ¶
MarshalJSON - marshaller for json
func (*NullBool) UnmarshalBSONValue ¶
func (*NullBool) UnmarshalEasyJSON ¶
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON - unmarshaller for json
type NullDuration ¶ added in v0.6.0
type NullDuration struct { Duration time.Duration Valid bool // Valid is true if Duration is not NULL }
NullDuration - nullable time.Duration
func Duration ¶ added in v0.6.2
func Duration(v int64) NullDuration
Duration - converts int64 to NullDuration
func (NullDuration) IsDefined ¶ added in v0.6.0
func (n NullDuration) IsDefined() bool
func (NullDuration) IsValid ¶ added in v0.6.0
func (n NullDuration) IsValid() bool
func (NullDuration) IsZero ¶ added in v0.6.0
func (n NullDuration) IsZero() bool
func (NullDuration) MarshalBSONValue ¶ added in v0.6.0
func (n NullDuration) MarshalBSONValue() (bsontype.Type, []byte, error)
func (NullDuration) MarshalEasyJSON ¶ added in v0.6.0
func (n NullDuration) MarshalEasyJSON(out *jwriter.Writer)
MarshalEasyJSON - marshaller for easyjson
func (NullDuration) MarshalJSON ¶ added in v0.6.0
func (n NullDuration) MarshalJSON() ([]byte, error)
MarshalJSON - marshaller for json
func (*NullDuration) Scan ¶ added in v0.6.0
func (n *NullDuration) Scan(value interface{}) error
func (*NullDuration) UnmarshalBSONValue ¶ added in v0.6.0
func (n *NullDuration) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
func (*NullDuration) UnmarshalEasyJSON ¶ added in v0.6.0
func (n *NullDuration) UnmarshalEasyJSON(in *jlexer.Lexer)
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullDuration) UnmarshalJSON ¶ added in v0.6.0
func (n *NullDuration) UnmarshalJSON(data []byte) error
UnmarshalJSON - unmarshaller for json
type NullFloat32 ¶
NullFloat32 - nullable float32
func Float32ToNullFloat32
deprecated
func Float32ToNullFloat32(v float32) NullFloat32
Float32ToNullFloat32 - converts float32 to NullFloat32
Deprecated: use shorter variant
func (NullFloat32) IsDefined ¶
func (n NullFloat32) IsDefined() bool
func (NullFloat32) IsValid ¶
func (n NullFloat32) IsValid() bool
func (NullFloat32) IsZero ¶
func (n NullFloat32) IsZero() bool
func (NullFloat32) MarshalBSONValue ¶
func (n NullFloat32) MarshalBSONValue() (bsontype.Type, []byte, error)
func (NullFloat32) MarshalEasyJSON ¶
func (n NullFloat32) MarshalEasyJSON(out *jwriter.Writer)
MarshalEasyJSON - marshaller for easyjson
func (NullFloat32) MarshalJSON ¶
func (n NullFloat32) MarshalJSON() ([]byte, error)
MarshalJSON - marshaller for json
func (*NullFloat32) Scan ¶
func (n *NullFloat32) Scan(value interface{}) error
Scan - scan value from sql driver
func (*NullFloat32) UnmarshalBSONValue ¶
func (n *NullFloat32) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
func (*NullFloat32) UnmarshalEasyJSON ¶
func (n *NullFloat32) UnmarshalEasyJSON(in *jlexer.Lexer)
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullFloat32) UnmarshalJSON ¶
func (n *NullFloat32) UnmarshalJSON(data []byte) error
UnmarshalJSON - unmarshaller for json
type NullFloat64 ¶
NullFloat64 - nullable float64
func Float64ToNullFloat64
deprecated
func Float64ToNullFloat64(v float64) NullFloat64
Float64ToNullFloat64 - converts float64 to NullFloat64
Deprecated: use shorter variant
func (NullFloat64) IsDefined ¶
func (n NullFloat64) IsDefined() bool
func (NullFloat64) IsValid ¶
func (n NullFloat64) IsValid() bool
func (NullFloat64) IsZero ¶
func (n NullFloat64) IsZero() bool
func (NullFloat64) MarshalBSONValue ¶
func (n NullFloat64) MarshalBSONValue() (bsontype.Type, []byte, error)
func (NullFloat64) MarshalEasyJSON ¶
func (n NullFloat64) MarshalEasyJSON(out *jwriter.Writer)
MarshalEasyJSON - marshaller for easyjson
func (NullFloat64) MarshalJSON ¶
func (n NullFloat64) MarshalJSON() ([]byte, error)
MarshalJSON - marshaller for json
func (*NullFloat64) Scan ¶
func (n *NullFloat64) Scan(value interface{}) error
Scan - scan value from sql driver
func (*NullFloat64) UnmarshalBSONValue ¶
func (n *NullFloat64) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
func (*NullFloat64) UnmarshalEasyJSON ¶
func (n *NullFloat64) UnmarshalEasyJSON(in *jlexer.Lexer)
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullFloat64) UnmarshalJSON ¶
func (n *NullFloat64) UnmarshalJSON(data []byte) error
UnmarshalJSON - unmarshaller for json
type NullInt ¶
NullInt - nullable int
func IntToNullInt
deprecated
func (NullInt) MarshalBSONValue ¶
func (NullInt) MarshalEasyJSON ¶
MarshalEasyJSON - marshaller for easyjson
func (NullInt) MarshalJSON ¶
MarshalJSON - marshaller for json
func (*NullInt) UnmarshalBSONValue ¶
func (*NullInt) UnmarshalEasyJSON ¶
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullInt) UnmarshalJSON ¶
UnmarshalJSON - unmarshaller for json
type NullInt16 ¶
NullInt16 - nullable int16
func Int16ToNullInt16
deprecated
func (NullInt16) MarshalBSONValue ¶
func (NullInt16) MarshalEasyJSON ¶
MarshalEasyJSON - marshaller for easyjson
func (NullInt16) MarshalJSON ¶
MarshalJSON - marshaller for json
func (*NullInt16) UnmarshalBSONValue ¶
func (*NullInt16) UnmarshalEasyJSON ¶
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullInt16) UnmarshalJSON ¶
UnmarshalJSON - unmarshaller for json
type NullInt32 ¶
NullInt32 - nullable int32
func Int32ToNullInt32
deprecated
func (NullInt32) MarshalBSONValue ¶
func (NullInt32) MarshalEasyJSON ¶
MarshalEasyJSON - marshaller for easyjson
func (NullInt32) MarshalJSON ¶
MarshalJSON - marshaller for json
func (*NullInt32) UnmarshalBSONValue ¶
func (*NullInt32) UnmarshalEasyJSON ¶
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullInt32) UnmarshalJSON ¶
UnmarshalJSON - unmarshaller for json
type NullInt64 ¶
NullInt64 - nullable int64
func Int64ToNullInt64
deprecated
func (NullInt64) MarshalBSONValue ¶
func (NullInt64) MarshalEasyJSON ¶
MarshalEasyJSON - marshaller for easyjson
func (NullInt64) MarshalJSON ¶
MarshalJSON - marshaller for json
func (*NullInt64) UnmarshalBSONValue ¶
func (*NullInt64) UnmarshalEasyJSON ¶
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON - unmarshaller for json
type NullInt8 ¶
NullInt8 - nullable int8
func Int8ToNullInt8
deprecated
func (NullInt8) MarshalBSONValue ¶
func (NullInt8) MarshalEasyJSON ¶
MarshalEasyJSON - marshaller for easyjson
func (NullInt8) MarshalJSON ¶
MarshalJSON - marshaller for json
func (*NullInt8) UnmarshalBSONValue ¶
func (*NullInt8) UnmarshalEasyJSON ¶
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullInt8) UnmarshalJSON ¶
UnmarshalJSON - unmarshaller for json
type NullString ¶
NullString - nullable string
func StringToNullString
deprecated
func StringToNullString(v string) NullString
StringToNullString - converts string to NullString
Deprecated: use shorter variant
func (NullString) IsDefined ¶
func (n NullString) IsDefined() bool
func (NullString) IsValid ¶
func (n NullString) IsValid() bool
func (NullString) IsZero ¶
func (n NullString) IsZero() bool
func (NullString) MarshalBSONValue ¶
func (n NullString) MarshalBSONValue() (bsontype.Type, []byte, error)
func (NullString) MarshalEasyJSON ¶
func (n NullString) MarshalEasyJSON(out *jwriter.Writer)
MarshalEasyJSON - marshaller for easyjson
func (NullString) MarshalJSON ¶
func (n NullString) MarshalJSON() ([]byte, error)
MarshalJSON - marshaller for json
func (*NullString) Scan ¶
func (ns *NullString) Scan(value interface{}) error
Scan - scan value from sql driver
func (*NullString) UnmarshalBSONValue ¶
func (n *NullString) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
func (*NullString) UnmarshalEasyJSON ¶
func (n *NullString) UnmarshalEasyJSON(in *jlexer.Lexer)
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullString) UnmarshalJSON ¶
func (n *NullString) UnmarshalJSON(data []byte) error
UnmarshalJSON - unmarshaller for json
type NullTime ¶
NullTime - nullable time.Time
func TimeToNullTime
deprecated
func (NullTime) MarshalBSONValue ¶
func (NullTime) MarshalEasyJSON ¶
MarshalEasyJSON - marshaller for easyjson
func (NullTime) MarshalJSON ¶
MarshalJSON - marshaller for json
func (*NullTime) UnmarshalBSONValue ¶
func (*NullTime) UnmarshalEasyJSON ¶
UnmarshalEasyJSON - unmarshaller for easyjson
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON - unmarshaller for json