jtypes

package module
v0.0.0-...-7b26abd Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

Go Report Card Go Reference

jtype

import "github.com/MicahParks/jtype"

Testing

Currently, the repository has >90% test coverage.

$ go test -cover -race
PASS
coverage: 91.2% of statements
ok      github.com/MicahParks/jtype     0.024s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type J

type J interface {
	*mail.Address | *regexp.Regexp | time.Duration | time.Time | *url.URL
}

J is a set of common Go types that can be marshaled and unmarshalled with this package.

type JType

type JType[T J] struct {
	// contains filtered or unexported fields
}

JType holds a generic J value. It can be used to marshal and unmarshal its value to and from JSON.

func New

func New[T J](v T, options Options) *JType[T]

New creates a new JType.

func (*JType[T]) Get

func (j *JType[T]) Get() T

Get returns the held value.

func (*JType[T]) MarshalJSON

func (j *JType[T]) MarshalJSON() ([]byte, error)

MarshalJSON helps implement the json.Marshaler interface.

func (*JType[T]) Set

func (j *JType[T]) Set(v T)

Set sets the held value.

func (*JType[T]) UnmarshalJSON

func (j *JType[T]) UnmarshalJSON(bytes []byte) error

UnmarshalJSON helps implement the json.Unmarshaler interface.

type Options

type Options struct {
	MailAddressAddressOnlyMarshal bool
	MailAddressLowerMarshal       bool
	MailAddressUpperMarshal       bool
	TimeFormatMarshal             string
	TimeFormatUnmarshal           string
}

Options is a set of options for a JType. It modifies the behavior of JSON marshal/unmarshal.

Jump to

Keyboard shortcuts

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