Conversion
The Conversion registry includes a collection of functions designed to convert one data type to another directly within your templates. This allows for seamless type transformations.
You can easily import all the functions from the conversion
registry by including the following import statement in your code
toBool
toBool converts a value from any types reasonably be converted to a boolean. Using the cast package.
Signature | |
Must version |
toInt
toInt converts a value into a int. Using the cast package.
Signature | |
Must version |
toInt64
toInt64 converts a value into a int64. Using the cast package.
Signature | |
Must version |
toUint
toUint converts a value into a uint. Utilizes the cast package for conversion.
Signature | |
Must version |
toUint64
toUint64 converts a value into a uint64. Utilizes the cast package for conversion.
Signature | |
Must version |
toFloat64
toFloat64 converts a value into a float64. Utilizes the cast package for conversion.
Signature | |
Must version |
toOctal
toOctal parses a value as an octal (base 8) integer.
Signature | |
Must version |
toString
toString converts a value to a string, handling various types effectively.
Signature | |
Must version |
Note: toString can handle various types as:
error
and outputerr.Error()
fmt.Stringer
and outputo.String()
toDate / toMustDate
toDate converts a string to a time.Time
object based on a format specification.
Signature | |
Must version |
This example will takes the "2024-05-10 11:12:42"
string and convert it with the layout "2006-01-02"
.
See more about Golang Layout on the official documentation.
toDuration
toDuration converts a value to a time.Duration
. Taking a possibly signed sequence of decimal numbers, each optional fraction and a unit suffix, such 300ms
, -1.5h
or 2h45m
.
Valid time units are ns
, us
(or µs
), ms
, s
, m
and h
.
Signature | |
Must version |
Deprecated functions
atoi ⚠️
[DEPRECATED] Use toInt
instead.
❌ No error handling
int ⚠️
[DEPRECATED] Use toInt
instead.
int64 ⚠️
[DEPRECATED] Use toInt64
instead.
float64 ⚠️
[DEPRECATED] Use toFloat64
instead.
Last updated