marshal

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: BSD-3-Clause Imports: 10 Imported by: 5

README

Various helper types for easier marshaling in Go language

GoDoc Build Status

Installation

Run go get resenje.org/marshal from command line.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDuration = errors.New("invalid duration")

ErrInvalidDuration is error returned if no duration can be encoded or decoded.

View Source
var ErrInvalidOctalMode = errors.New("invalid file mode in octal representation")

ErrInvalidOctalMode is error returned if no file mode can be encoded or decoded.

View Source
var ErrInvalidURL = errors.New("invalid url")

ErrInvalidURL is error returned if no URL can be encoded or decoded.

Functions

This section is empty.

Types

type Bytes

type Bytes float64

Bytes is a helper type that represents length of data in bytes.

func (Bytes) Bytes

func (b Bytes) Bytes() float64

Bytes returns an integer value of length of bytes.

func (Bytes) MarshalJSON

func (b Bytes) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface. It marshals a string representation of length of bytes.

func (Bytes) MarshalText

func (b Bytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface. It marshals a string representation of length of bytes.

func (*Bytes) UnmarshalJSON

func (b *Bytes) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It parses length of bytes string.

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface. It parses length of bytes string.

type Checkbox

type Checkbox bool

Checkbox is a helper type to unmarshal value from HTML checkbox into boolean.

func (Checkbox) Bool

func (c Checkbox) Bool() bool

Bool returns boolean value of a Checkbox type.

func (Checkbox) MarshalJSON

func (c Checkbox) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Checkbox.

  • "on" if it is checked
  • false if it is not checked

func (*Checkbox) UnmarshalJSON

func (c *Checkbox) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the JSON-encoded data and sets Checkbox to true or false.

type Duration

type Duration time.Duration

Duration is a helper type that wraps time.Duration to JSON encode and decode durations in humanly readable form.

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns time.Duration of a Duration value.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface. It marshals a string representation of time.Duration.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface. It marshals a string representation of time.Duration.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It parses time.Duration string.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface. It parses time.Duration string.

type Mode

type Mode int

Mode is a helper type that can JSON encode and decode integers used as file mode in octal representation.

func (Mode) FileMode

func (m Mode) FileMode() os.FileMode

FileMode returns os.FileMode of Mode value.

func (Mode) MarshalJSON

func (m Mode) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface. It marshals a string of octal representation of integer.

func (Mode) MarshalText

func (m Mode) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface. It marshals a string of octal representation of integer.

func (*Mode) UnmarshalJSON

func (m *Mode) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It parses octal representations of integer.

func (*Mode) UnmarshalText

func (m *Mode) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface. It parses octal representations of integer.

type URL

type URL url.URL

URL is a helper type that wraps url.URL to JSON encode and decode URLs.

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface. It marshals a string representation of url.URL.

func (URL) MarshalText

func (u URL) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface. It marshals a string representation of url.URL.

func (URL) URL

func (u URL) URL() *url.URL

URL returns url.URL of a URL value.

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It parses url.URL string.

func (*URL) UnmarshalText

func (u *URL) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface. It parses url.URL string.

Jump to

Keyboard shortcuts

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