pair

package
v0.0.0-...-ec3616b Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: 0BSD Imports: 1 Imported by: 0

Documentation

Overview

Package pair can represent 1:1 mappings between two different APIs, such that validation errors are transformed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Const

func Const[T any](value T) *T

Const returns a constant value, that is assumed to always be present on one side of an API pairing.

func Make

func Make[From, Into any](registry Registry, mapping func(from *From, into *Into) []Field) (func(From) Into, func(Into) From, func(error) error)

Make a 1:1 mapping function that maps from -> into and into -> from, as well as an error wrapper that transforms field-specific errors from one API space into the other.

Types

type Error

type Error interface {
	FieldName() string
	WithFieldNameSetTo(string) error
}

Error that relates to a particular field from one API model.

type Field

type Field struct {
	// contains filtered or unexported fields
}

Field represents a 1:1 mapping between two fields.

func Bool

func Bool[From ~bool, Into ~bool](from *From, into *Into) Field

Bool pairs two bool fields together.

func Complex128

func Complex128[From ~complex128, Into ~complex128](from *From, into *Into) Field

Complex128 pairs two complex128 fields together.

func Complex64

func Complex64[From ~complex64, Into ~complex64](from *From, into *Into) Field

Complex64 pairs two complex64 fields together.

func Float32

func Float32[From ~float32, Into ~float32](from *From, into *Into) Field

Float32 pairs two float32 fields together.

func Float64

func Float64[From ~float64, Into ~float64](from *From, into *Into) Field

Float64 pairs two float64 fields together.

func Int

func Int[From ~int, Into ~int](from *From, into *Into) Field

Int pairs two int fields together.

func Int16

func Int16[From ~int16, Into ~int16](from *From, into *Into) Field

Int16 pairs two int16 fields together.

func Int32

func Int32[From ~int32, Into ~int32](from *From, into *Into) Field

Int32 pairs two int32 fields together.

func Int64

func Int64[From ~int64, Into ~int64](from *From, into *Into) Field

Int64 pairs two int64 fields together.

func Int8

func Int8[From ~int8, Into ~int8](from *From, into *Into) Field

Int8 pairs two int8 fields together.

func Map

func Map[FromKey, IntoKey comparable, FromVal, IntoVal any](
	from *map[FromKey]FromVal, into *map[IntoKey]IntoVal,
	keyRule func(*FromKey, *IntoKey) Field,
	valRule func(*FromVal, *IntoVal) Field,
) Field

Map pairs two map fields together.

func Slice

func Slice[From, Into any](from *[]From, into *[]Into, rule func(*From, *Into) Field) Field

Slice pairs two slice fields together.

func String

func String[From ~string, Into ~string](from *From, into *Into) Field

String pairs two string fields together.

func Uint

func Uint[From ~uint, Into ~uint](from *From, into *Into) Field

Uint pairs two uint fields together.

func Uint16

func Uint16[From ~uint16, Into ~uint16](from *From, into *Into) Field

Uint16 pairs two uint16 fields together.

func Uint32

func Uint32[From ~uint32, Into ~uint32](from *From, into *Into) Field

Uint32 pairs two uint32 fields together.

func Uint64

func Uint64[From ~uint64, Into ~uint64](from *From, into *Into) Field

Uint64 pairs two uint64 fields together.

func Uint8

func Uint8[From ~uint8, Into ~uint8](from *From, into *Into) Field

Uint8 pairs two uint8 fields together.

func Uintptr

func Uintptr[From ~uintptr, Into ~uintptr](from *From, into *Into) Field

Uintptr pairs two uintptr fields together.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry of functions that convert errors into [Error]s.

func (*Registry) Register

func (registry *Registry) Register(fn func(error) Error)

Register a function that returns an Error from an error, if the function returns nil, the error will not be converted.

Jump to

Keyboard shortcuts

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