jawn

package module
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2020 License: MIT Imports: 15 Imported by: 0

README

jawn - just a welcome nullable

A fork of kak-tus/nan to add Zeroer interface support.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mashaler

type Mashaler interface {
	MarshalBSONValue() (bsontype.Type, []byte, error)
	UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error
}

type NullBool

type NullBool struct {
	Bool  bool
	Valid bool // Valid is true if Bool is not NULL
}

NullBool - nullable bool

func Bool

func Bool(v bool) NullBool

Bool - converts bool to NullBool

func BoolToNullBool deprecated

func BoolToNullBool(v bool) NullBool

BoolToNullBool - converts bool to NullBool

Deprecated: use shorter variant

func (NullBool) IsDefined

func (n NullBool) IsDefined() bool

func (NullBool) IsValid

func (n NullBool) IsValid() bool

func (NullBool) IsZero

func (n NullBool) IsZero() bool

func (NullBool) MarshalBSONValue

func (n NullBool) MarshalBSONValue() (bsontype.Type, []byte, error)

func (NullBool) MarshalEasyJSON

func (n NullBool) MarshalEasyJSON(out *jwriter.Writer)

MarshalEasyJSON - marshaller for easyjson

func (NullBool) MarshalJSON

func (n NullBool) MarshalJSON() ([]byte, error)

MarshalJSON - marshaller for json

func (*NullBool) Scan

func (n *NullBool) Scan(value interface{}) error

Scan - scan value from sql driver

func (*NullBool) UnmarshalBSONValue

func (n *NullBool) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error

func (*NullBool) UnmarshalEasyJSON

func (n *NullBool) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON - unmarshaller for easyjson

func (*NullBool) UnmarshalJSON

func (n *NullBool) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshaller for json

func (NullBool) Value

func (n NullBool) Value() (driver.Value, error)

Value implements the driver Valuer interface.

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

func (NullDuration) Value added in v0.6.0

func (n NullDuration) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullFloat32

type NullFloat32 struct {
	Float32 float32
	Valid   bool // Valid is true if Float32 is not NULL
}

NullFloat32 - nullable float32

func Float32

func Float32(v float32) NullFloat32

Float32 - converts float32 to NullFloat32

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

func (NullFloat32) Value

func (n NullFloat32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullFloat64

type NullFloat64 struct {
	Float64 float64
	Valid   bool // Valid is true if Float64 is not NULL
}

NullFloat64 - nullable float64

func Float64

func Float64(v float64) NullFloat64

Float64 - converts float64 to NullFloat64

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

func (NullFloat64) Value

func (n NullFloat64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt

type NullInt struct {
	Int   int
	Valid bool // Valid is true if Int8 is not NULL
}

NullInt - nullable int

func Int

func Int(v int) NullInt

Int - converts int to NullInt

func IntToNullInt deprecated

func IntToNullInt(v int) NullInt

IntToNullInt - converts int to NullInt

Deprecated: use shorter variant

func (NullInt) IsDefined

func (n NullInt) IsDefined() bool

func (NullInt) IsValid

func (n NullInt) IsValid() bool

func (NullInt) IsZero

func (n NullInt) IsZero() bool

func (NullInt) MarshalBSONValue

func (n NullInt) MarshalBSONValue() (bsontype.Type, []byte, error)

func (NullInt) MarshalEasyJSON

func (n NullInt) MarshalEasyJSON(out *jwriter.Writer)

MarshalEasyJSON - marshaller for easyjson

func (NullInt) MarshalJSON

func (n NullInt) MarshalJSON() ([]byte, error)

MarshalJSON - marshaller for json

func (*NullInt) Scan

func (n *NullInt) Scan(value interface{}) error

Scan - scan value from sql driver

func (*NullInt) UnmarshalBSONValue

func (n *NullInt) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error

func (*NullInt) UnmarshalEasyJSON

func (n *NullInt) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON - unmarshaller for easyjson

func (*NullInt) UnmarshalJSON

func (n *NullInt) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshaller for json

func (NullInt) Value

func (n NullInt) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt16

type NullInt16 struct {
	Int16 int16
	Valid bool // Valid is true if Int16 is not NULL
}

NullInt16 - nullable int16

func Int16

func Int16(v int16) NullInt16

Int16 - converts int16 to NullInt16

func Int16ToNullInt16 deprecated

func Int16ToNullInt16(v int16) NullInt16

Int16ToNullInt16 - converts int16 to NullInt16

Deprecated: use shorter variant

func (NullInt16) IsDefined

func (n NullInt16) IsDefined() bool

func (NullInt16) IsValid

func (n NullInt16) IsValid() bool

func (NullInt16) IsZero

func (n NullInt16) IsZero() bool

func (NullInt16) MarshalBSONValue

func (n NullInt16) MarshalBSONValue() (bsontype.Type, []byte, error)

func (NullInt16) MarshalEasyJSON

func (n NullInt16) MarshalEasyJSON(out *jwriter.Writer)

MarshalEasyJSON - marshaller for easyjson

func (NullInt16) MarshalJSON

func (n NullInt16) MarshalJSON() ([]byte, error)

MarshalJSON - marshaller for json

func (*NullInt16) Scan

func (n *NullInt16) Scan(value interface{}) error

Scan - scan value from sql driver

func (*NullInt16) UnmarshalBSONValue

func (n *NullInt16) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error

func (*NullInt16) UnmarshalEasyJSON

func (n *NullInt16) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON - unmarshaller for easyjson

func (*NullInt16) UnmarshalJSON

func (n *NullInt16) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshaller for json

func (NullInt16) Value

func (n NullInt16) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt32

type NullInt32 struct {
	Int32 int32
	Valid bool // Valid is true if Int32 is not NULL
}

NullInt32 - nullable int32

func Int32

func Int32(v int32) NullInt32

Int32 - converts int32 to NullInt32

func Int32ToNullInt32 deprecated

func Int32ToNullInt32(v int32) NullInt32

Int32ToNullInt32 - converts int32 to NullInt32

Deprecated: use shorter variant

func (NullInt32) IsDefined

func (n NullInt32) IsDefined() bool

func (NullInt32) IsValid

func (n NullInt32) IsValid() bool

func (NullInt32) IsZero

func (n NullInt32) IsZero() bool

func (NullInt32) MarshalBSONValue

func (n NullInt32) MarshalBSONValue() (bsontype.Type, []byte, error)

func (NullInt32) MarshalEasyJSON

func (n NullInt32) MarshalEasyJSON(out *jwriter.Writer)

MarshalEasyJSON - marshaller for easyjson

func (NullInt32) MarshalJSON

func (n NullInt32) MarshalJSON() ([]byte, error)

MarshalJSON - marshaller for json

func (*NullInt32) Scan

func (n *NullInt32) Scan(value interface{}) error

Scan - scan value from sql driver

func (*NullInt32) UnmarshalBSONValue

func (n *NullInt32) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error

func (*NullInt32) UnmarshalEasyJSON

func (n *NullInt32) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON - unmarshaller for easyjson

func (*NullInt32) UnmarshalJSON

func (n *NullInt32) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshaller for json

func (NullInt32) Value

func (n NullInt32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt64

type NullInt64 struct {
	Int64 int64
	Valid bool // Valid is true if Int64 is not NULL
}

NullInt64 - nullable int64

func Int64

func Int64(v int64) NullInt64

Int64 - converts int64 to NullInt64

func Int64ToNullInt64 deprecated

func Int64ToNullInt64(v int64) NullInt64

Int64ToNullInt64 - converts int64 to NullInt64

Deprecated: use shorter variant

func (NullInt64) IsDefined

func (n NullInt64) IsDefined() bool

func (NullInt64) IsValid

func (n NullInt64) IsValid() bool

func (NullInt64) IsZero

func (n NullInt64) IsZero() bool

func (NullInt64) MarshalBSONValue

func (n NullInt64) MarshalBSONValue() (bsontype.Type, []byte, error)

func (NullInt64) MarshalEasyJSON

func (n NullInt64) MarshalEasyJSON(out *jwriter.Writer)

MarshalEasyJSON - marshaller for easyjson

func (NullInt64) MarshalJSON

func (n NullInt64) MarshalJSON() ([]byte, error)

MarshalJSON - marshaller for json

func (*NullInt64) Scan

func (n *NullInt64) Scan(value interface{}) error

Scan - scan value from sql driver

func (*NullInt64) UnmarshalBSONValue

func (n *NullInt64) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error

func (*NullInt64) UnmarshalEasyJSON

func (n *NullInt64) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON - unmarshaller for easyjson

func (*NullInt64) UnmarshalJSON

func (n *NullInt64) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshaller for json

func (NullInt64) Value

func (n NullInt64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullInt8

type NullInt8 struct {
	Int8  int8
	Valid bool // Valid is true if Int8 is not NULL
}

NullInt8 - nullable int8

func Int8

func Int8(v int8) NullInt8

Int8 - converts int8 to NullInt8

func Int8ToNullInt8 deprecated

func Int8ToNullInt8(v int8) NullInt8

Int8ToNullInt8 - converts int8 to NullInt8

Deprecated: use shorter variant

func (NullInt8) IsDefined

func (n NullInt8) IsDefined() bool

func (NullInt8) IsValid

func (n NullInt8) IsValid() bool

func (NullInt8) IsZero

func (n NullInt8) IsZero() bool

func (NullInt8) MarshalBSONValue

func (n NullInt8) MarshalBSONValue() (bsontype.Type, []byte, error)

func (NullInt8) MarshalEasyJSON

func (n NullInt8) MarshalEasyJSON(out *jwriter.Writer)

MarshalEasyJSON - marshaller for easyjson

func (NullInt8) MarshalJSON

func (n NullInt8) MarshalJSON() ([]byte, error)

MarshalJSON - marshaller for json

func (*NullInt8) Scan

func (n *NullInt8) Scan(value interface{}) error

Scan - scan value from sql driver

func (*NullInt8) UnmarshalBSONValue

func (n *NullInt8) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error

func (*NullInt8) UnmarshalEasyJSON

func (n *NullInt8) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON - unmarshaller for easyjson

func (*NullInt8) UnmarshalJSON

func (n *NullInt8) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshaller for json

func (NullInt8) Value

func (n NullInt8) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullString

type NullString struct {
	String string
	Valid  bool // Valid is true if String is not NULL
}

NullString - nullable string

func String

func String(v string) NullString

String - converts string to NullString

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

func (NullString) Value

func (ns NullString) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

NullTime - nullable time.Time

func Time

func Time(v time.Time) NullTime

Time - converts time.Time to NullTime

func TimeToNullTime deprecated

func TimeToNullTime(v time.Time) NullTime

TimeToNullTime - converts time.Time to NullTime

Deprecated: use shorter variant

func (NullTime) IsDefined

func (n NullTime) IsDefined() bool

func (NullTime) IsValid

func (n NullTime) IsValid() bool

func (NullTime) IsZero

func (n NullTime) IsZero() bool

func (NullTime) MarshalBSONValue

func (n NullTime) MarshalBSONValue() (bsontype.Type, []byte, error)

func (NullTime) MarshalEasyJSON

func (n NullTime) MarshalEasyJSON(out *jwriter.Writer)

MarshalEasyJSON - marshaller for easyjson

func (NullTime) MarshalJSON

func (n NullTime) MarshalJSON() ([]byte, error)

MarshalJSON - marshaller for json

func (*NullTime) Scan

func (n *NullTime) Scan(value interface{}) error

Scan - scan value from sql driver

func (*NullTime) UnmarshalBSONValue

func (n *NullTime) UnmarshalBSONValue(bType bsontype.Type, bBytes []byte) error

func (*NullTime) UnmarshalEasyJSON

func (n *NullTime) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON - unmarshaller for easyjson

func (*NullTime) UnmarshalJSON

func (n *NullTime) UnmarshalJSON(data []byte) error

UnmarshalJSON - unmarshaller for json

func (NullTime) Value

func (n NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Validator

type Validator interface {
	IsValid() bool
}

Validator is implemented by all jawn types and returns Valid field

type Zeroer

type Zeroer interface {
	IsZero() bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL