null

package
v0.0.0-...-0380b65 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package null defines Null variants of the primitive types. It is supposed that users may define their own types to satisfy their needs. The purpose of these types is to give the basic idea on how to define custom types.

The advantage of these types over original database/sql Null* types is that (un)marshaling to JSON works as expected. So, instead of:

{
	"title": {
		"Valid": true,
		"String": "Octopus"
	},
	"description": {
		"Valid": false,
		"String": ""
	}
}

it is now marshaled like this:

{
	"title": "Octopus",
	"description": null
}

Other kinds of marshaling (e.g. XML) are not implemented yet. Anyway, it is not possible (nor desired) to cover everyone's needs for Null* types, so it is recommended to define own types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	sql.NullBool
}

Bool is a type that can be null or a bool.

func (*Bool) MarshalJSON

func (n *Bool) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a Bool to JSON.

func (*Bool) UnmarshalJSON

func (n *Bool) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a Bool from JSON.

type Float64

type Float64 struct {
	sql.NullFloat64
}

Float64 is a type that can be null or a float64.

func (*Float64) MarshalJSON

func (n *Float64) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a Float64 to JSON.

func (*Float64) UnmarshalJSON

func (n *Float64) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a Float64 from JSON.

type Int64

type Int64 struct {
	sql.NullInt64
}

Int64 is a type that can be null or an int.

func (*Int64) MarshalJSON

func (n *Int64) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a Int64 to JSON.

func (*Int64) UnmarshalJSON

func (n *Int64) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a Int64 from JSON.

type String

type String struct {
	sql.NullString
}

String is a type that can be null or a string.

func (*String) MarshalJSON

func (n *String) MarshalJSON() ([]byte, error)

MarshalJSON correctly serializes a String to JSON.

func (*String) UnmarshalJSON

func (n *String) UnmarshalJSON(b []byte) error

UnmarshalJSON correctly deserializes a String from JSON.

Jump to

Keyboard shortcuts

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