go4.orggo4.org/types Index | Files

package types

import "go4.org/types"

Package types provides various common types.

Index

Variables

EmptyBody is a ReadCloser that returns EOF on Read and does nothing on Close.

var NopCloser io.Closer = CloseFunc(func() error { return nil })

NopCloser is an io.Closer that does nothing.

Functions

func NewOnceCloser

func NewOnceCloser(c io.Closer) io.Closer

NewOnceCloser returns a Closer wrapping c which only calls Close on c once. Subsequent calls to Close return nil.

Types

type ByTime

type ByTime []time.Time

ByTime sorts times.

func (ByTime) Len

func (s ByTime) Len() int

func (ByTime) Less

func (s ByTime) Less(i, j int) bool

func (ByTime) Swap

func (s ByTime) Swap(i, j int)

type CloseFunc

type CloseFunc func() error

CloseFunc implements io.Closer with a function.

func (CloseFunc) Close

func (fn CloseFunc) Close() error

type Time3339

type Time3339 time.Time

Time3339 is a time.Time which encodes to and from JSON as an RFC 3339 time in UTC.

func ParseTime3339OrNil

func ParseTime3339OrNil(v string) *Time3339

func ParseTime3339OrZero

func ParseTime3339OrZero(v string) Time3339

ParseTime3339OrZero parses a string in RFC3339 format. If it's invalid, the zero time value is returned instead.

func (*Time3339) IsAnyZero

func (t *Time3339) IsAnyZero() bool

IsAnyZero returns whether the time is Go zero or Unix zero.

func (Time3339) MarshalJSON

func (t Time3339) MarshalJSON() ([]byte, error)

func (Time3339) String

func (t Time3339) String() string

func (Time3339) Time

func (t Time3339) Time() time.Time

Time returns the time as a time.Time with slightly less stutter than a manual conversion.

func (*Time3339) UnmarshalJSON

func (t *Time3339) UnmarshalJSON(b []byte) error

Source Files

types.go

Version
v0.0.0-20230225012048-214862532bf5 (latest)
Published
Feb 25, 2023
Platform
linux/amd64
Imports
8 packages
Last checked
2 months ago

Tools for package owners.