typutil

package module
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2023 License: MIT Imports: 16 Imported by: 11

README

GoDoc

type conversion utils

This is useful when dealing with json parsed types for example.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAssignDestNotPointer      = errors.New("assign destination must be a pointer")
	ErrAssignImpossible          = errors.New("the requested assign is not possible")
	ErrNilPointerRead            = errors.New("attempt to read from a nil pointer")
	ErrEmptyValue                = errors.New("validator: value must not be empty")
	ErrDestinationNotAddressable = errors.New("assign: destination cannot be addressed")
	ErrStructPtrRequired         = errors.New("parameter must be a pointer to a struct")
)

Functions

func AsBool

func AsBool(v any) bool

some helper functions related to numbers

func AsByteArray added in v0.1.14

func AsByteArray(v any) ([]byte, bool)

func AsFloat

func AsFloat(v any) (float64, bool)

func AsInt

func AsInt(v any) (int64, bool)

func AsNumber

func AsNumber(v any) (any, bool)

func AsString added in v0.1.2

func AsString(v any) (string, bool)

func AsUint

func AsUint(v any) (uint64, bool)

func Assign added in v0.1.5

func Assign(dst, src any) error

func BaseType added in v0.1.4

func BaseType(v any) any

BaseType attempts to convert v into its base type, that is if v is a type that is defined as `type foo string`, a simple string will be returned.

func SetValidator added in v0.1.6

func SetValidator[T any](validator string, fnc func(T) error)

SetValidator sets the given function as validator with the given name. This should be typically called in init()

func SetValidatorArgs added in v0.1.13

func SetValidatorArgs(validator string, fnc any)

func Validate added in v0.1.10

func Validate(obj any) error

Validate accept any struct as argument and returns if the struct is valid. The parameter should be a pointer to the struct so validators can edit values.

Types

This section is empty.

Jump to

Keyboard shortcuts

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