adapter

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Provides adapters for built-in types and interfaces.

The majority of the adapters are simple string to type style converters. BoolUnmarshal and MarshalBool are examples of the simple converters.

There is also a special adapter pair that enable the encoding.TextMarshaler and encoding.TextUnmarshaler interfaces: TextUnmarshal() and MarshalText().

Both TextUnmarshal and MarshalText take a Matcher that allows you to control which objects should use their provided functions. Generally you will want to use the provided methods, but sometimes they either don't work or don't fit the use case right and replacing them is desired. A Matcher is how you can block the provided methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(t any) bool

All matches all the possible types.

func AllButTime

func AllButTime(t any) bool

AllButTime matches all types except the time.Time and *time.Time types. By excluding these types, a custom TimeUnmarshal() and MarshalTime() can be set and used reliably.

func BoolUnmarshal added in v0.20.0

func BoolUnmarshal() goschtalt.UnmarshalOption

BoolUnmarshal converts a string to a bool or *bool if possible, or returns an error indicating the failure. The case is ignored, but only the following values are accepted: 'f', 'false', 't', 'true'

func DurationUnmarshal

func DurationUnmarshal() goschtalt.UnmarshalOption

DurationUnmarshal converts a string to a time.Duration or *time.Duration if possible, or returns an error indicating the failure.

func FloatUnmarshal added in v0.20.0

func FloatUnmarshal() goschtalt.UnmarshalOption

FloatUnmarshal converts a string to a float32/float64 or *float32/*float64 if possible, or returns an error indicating the failure.

func IntUnmarshal added in v0.20.0

func IntUnmarshal() goschtalt.UnmarshalOption

IntUnmarshal converts a string to a int/int8/int16/int32/int64 or a pointer version of them if possible, or returns an error indicating the failure. Up to triple pointers are supported.

func MarshalBool added in v0.20.0

func MarshalBool() goschtalt.ValueOption

MarshalBool converts a bool into its configuration form. The configuration form is a string of value 'true' or 'false'.

func MarshalDuration

func MarshalDuration() goschtalt.ValueOption

MarshalDuration converts a time.Duration into its configuration form. The configuration form is a string.

func MarshalFloat added in v0.20.0

func MarshalFloat() goschtalt.ValueOption

MarshalFloat converts a float32/float64 into its string configuration form.

func MarshalInt added in v0.20.0

func MarshalInt() goschtalt.ValueOption

MarshalInt converts a int/int8/int16/int32/int64 into its string configuration form.

func MarshalText

func MarshalText(m Matcher) goschtalt.ValueOption

MarshalText uses the TextUnmarshaler() method if present for an object if the matcher function allows. The only configuration value type allowed is a string.

func MarshalTime

func MarshalTime(layout string) goschtalt.ValueOption

MarshalTime converts a time.Time into its configuration form. The configuration form is a string matching the specified layout.

func MarshalUint added in v0.20.0

func MarshalUint() goschtalt.ValueOption

MarshalUint converts a uint/uint8/uint16/uint32/uint64/uintptr into its string configuration form.

func TextUnmarshal

func TextUnmarshal(m Matcher) goschtalt.UnmarshalOption

TextUnmarshal uses the TextUnmarshaler() method if present for an object that the matcher function allows. The only configuration value type allowed is a string.

func TimeUnmarshal

func TimeUnmarshal(layout string) goschtalt.UnmarshalOption

TimeUnmarshal converts a string to a time.Time if possible, or returns an error indicating the failure. The specified layout is used as the string form.

func UintUnmarshal added in v0.20.0

func UintUnmarshal() goschtalt.UnmarshalOption

UintUnmarshal converts a string to a uint/uint8/uint16/uint32/uint64/uintptr or a pointer version of them if possible, or returns an error indicating the failure. Up to triple pointers are supported.

Types

type Matcher

type Matcher func(t any) bool

Matcher provides a simple way to include or exclude types that are converted via TextUnmarshal() or MarshalText().

Jump to

Keyboard shortcuts

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