convert

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package convert contains common conversion interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter interface {

	// Bool returns the bool representation from the given interface value.
	// Returns the default value of false and an error on failure.
	Bool(from interface{}) (to bool, err error)

	// Duration returns the time.Duration representation from the given
	// interface{} value. Returns the default value of 0 and an error on failure.
	Duration(from interface{}) (to time.Duration, err error)

	// Float32 returns the float32 representation from the given empty interface
	// value. Returns the default value of 0 and an error on failure.
	Float32(from interface{}) (to float32, err error)

	// Float64 returns the float64 representation from the given interface
	// value. Returns the default value of 0 and an error on failure.
	Float64(from interface{}) (to float64, err error)

	// Infer will perform conversion by inferring the conversion operation from
	// a pointer to a supported T of the `into` param.
	Infer(into, from interface{}) error

	// Int returns the int representation from the given empty interface
	// value. Returns the default value of 0 and an error on failure.
	Int(from interface{}) (to int, err error)

	// Int8 returns the int8 representation from the given empty interface
	// value. Returns the default value of 0 and an error on failure.
	Int8(from interface{}) (to int8, err error)

	// Int16 returns the int16 representation from the given empty interface
	// value. Returns the default value of 0 and an error on failure.
	Int16(from interface{}) (to int16, err error)

	// Int32 returns the int32 representation from the given empty interface
	// value. Returns the default value of 0 and an error on failure.
	Int32(from interface{}) (to int32, err error)

	// Int64 returns the int64 representation from the given interface
	// value. Returns the default value of 0 and an error on failure.
	Int64(from interface{}) (to int64, err error)

	// String returns the string representation from the given interface
	// value and can not fail. An error is provided only for API cohesion.
	String(from interface{}) (to string, err error)

	// Time returns the time.Time{} representation from the given interface
	// value. Returns an empty time.Time struct and an error on failure.
	Time(from interface{}) (to time.Time, err error)

	// Uint returns the uint representation from the given empty interface
	// value. Returns the default value of 0 and an error on failure.
	Uint(from interface{}) (to uint, err error)

	// Uint8 returns the uint8 representation from the given empty interface
	// value. Returns the default value of 0 and an error on failure.
	Uint8(from interface{}) (to uint8, err error)

	// Uint16 returns the uint16 representation from the given empty interface
	// value. Returns the default value of 0 and an error on failure.
	Uint16(from interface{}) (to uint16, err error)

	// Uint32 returns the uint32 representation from the given empty interface
	// value. Returns the default value of 0 and an error on failure.
	Uint32(from interface{}) (to uint32, err error)

	// Uint64 returns the uint64 representation from the given interface
	// value. Returns the default value of 0 and an error on failure.
	Uint64(from interface{}) (to uint64, err error)
}

Converter supports conversion across Go types.

type FnConv

type FnConv func(into, from interface{}) error

func WithError

func WithError(err error, fn FnConv) FnConv

func WithErrorAfter

func WithErrorAfter(err error, after int, fn FnConv) FnConv

func (FnConv) Bool

func (fn FnConv) Bool(from interface{}) (out bool, err error)

func (FnConv) Duration

func (fn FnConv) Duration(from interface{}) (out time.Duration, err error)

func (FnConv) Float32

func (fn FnConv) Float32(from interface{}) (out float32, err error)

func (FnConv) Float64

func (fn FnConv) Float64(from interface{}) (out float64, err error)

func (FnConv) Infer

func (fn FnConv) Infer(into, from interface{}) (err error)

func (FnConv) Int

func (fn FnConv) Int(from interface{}) (out int, err error)

func (FnConv) Int16

func (fn FnConv) Int16(from interface{}) (out int16, err error)

func (FnConv) Int32

func (fn FnConv) Int32(from interface{}) (out int32, err error)

func (FnConv) Int64

func (fn FnConv) Int64(from interface{}) (out int64, err error)

func (FnConv) Int8

func (fn FnConv) Int8(from interface{}) (out int8, err error)

func (FnConv) Map

func (fn FnConv) Map(into, from interface{}) (err error)

func (FnConv) Slice

func (fn FnConv) Slice(into, from interface{}) (err error)

func (FnConv) String

func (fn FnConv) String(from interface{}) (out string, err error)

func (FnConv) Struct

func (fn FnConv) Struct(into, from interface{}) (err error)

func (FnConv) Time

func (fn FnConv) Time(from interface{}) (out time.Time, err error)

func (FnConv) Uint

func (fn FnConv) Uint(from interface{}) (out uint, err error)

func (FnConv) Uint16

func (fn FnConv) Uint16(from interface{}) (out uint16, err error)

func (FnConv) Uint32

func (fn FnConv) Uint32(from interface{}) (out uint32, err error)

func (FnConv) Uint64

func (fn FnConv) Uint64(from interface{}) (out uint64, err error)

func (FnConv) Uint8

func (fn FnConv) Uint8(from interface{}) (out uint8, err error)

Jump to

Keyboard shortcuts

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