jsonutil

package module
v0.0.0-...-d44b59f Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2016 License: MIT Imports: 2 Imported by: 39

README

jsonutil

Build Status GoDoc

Collection of common custom types used with Golang's json package.

See the documentation for details.

License

jsonutil is licensed under the MIT license, see the LICENSE file.

Documentation

Overview

Package jsonutil provides a collection of types implementing the json.Unmarshaler and json.Marshaler interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration struct {
	time.Duration
}

Duration is a wrapper around time.Duration which implements json.Unmarshaler and json.Marshaler. It marshals and unmarshals the duration as a string in the format accepted by time.ParseDuration and returned by time.Duration.String.

func FromDuration

func FromDuration(d time.Duration) Duration

FromDuration is a convenience factory to create a Duration instance from the given time.Duration value.

func (Duration) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface. The duration is a quoted-string in the format accepted by time.ParseDuration and returned by time.Duration.String.

func (*Duration) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface. The duration is expected to be a quoted-string of a duration in the format accepted by time.ParseDuration.

Jump to

Keyboard shortcuts

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