conv

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package conv provides fast type conversions. Overflow and non-finite (NaN/Inf) inputs error; a float-to-integer conversion truncates toward zero.

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeLayouts = []string{
	time.RFC3339Nano,
	time.RFC3339,
	"2006-01-02 15:04:05",
	"2006-01-02T15:04:05",
	"2006-01-02",
	"2006/01/02",
	"15:04:05",
}

DefaultTimeLayouts are tried in order by ToTime when no layout is given.

View Source
var ErrConvert = errors.New("conv: cannot convert value")

ErrConvert is the base error for a failed conversion.

Functions

func ParseBool

func ParseBool(s string) (bool, error)

ParseBool parses the usual truthy/falsy tokens (case-insensitive, trimmed); unknown input errors.

func ToBool

func ToBool(v any) (bool, error)

ToBool converts v to a bool; truthy/falsy strings are accepted, numbers are true when non-zero.

func ToFloat

func ToFloat(v any) (float64, error)

ToFloat converts v to a float64; non-finite results (NaN/Inf) are rejected.

func ToInt

func ToInt(v any) (int64, error)

ToInt converts v to an int64; overflow/non-finite error, floats truncate toward zero.

func ToString

func ToString(v any) string

ToString converts v to its string representation; pointers are dereferenced (nil yields "").

func ToTime

func ToTime(v any, layouts ...string) (time.Time, error)

ToTime converts v to a time.Time (integers are Unix seconds); results are UTC so all paths agree.

func ToUint

func ToUint(v any) (uint64, error)

ToUint converts v to a uint64; negative/overflow/non-finite error, floats truncate toward zero.

Types

This section is empty.

Jump to

Keyboard shortcuts

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