Documentation ¶
Index ¶
- type ConversionRegistry
- func (or *ConversionRegistry) LinkHandler(fh sprout.Handler) error
- func (cr *ConversionRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error
- func (cr *ConversionRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
- func (cr *ConversionRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
- func (cr *ConversionRegistry) ToBool(v any) (bool, error)
- func (cr *ConversionRegistry) ToDate(fmt, str string) (time.Time, error)
- func (cr *ConversionRegistry) ToDuration(v any) (time.Duration, error)
- func (cr *ConversionRegistry) ToFloat64(v any) (float64, error)
- func (cr *ConversionRegistry) ToInt(v any) (int, error)
- func (cr *ConversionRegistry) ToInt64(v any) (int64, error)
- func (cr *ConversionRegistry) ToOctal(v any) (int64, error)
- func (cr *ConversionRegistry) ToString(v any) string
- func (cr *ConversionRegistry) ToUint(v any) (uint, error)
- func (cr *ConversionRegistry) ToUint64(v any) (uint64, error)
- func (or *ConversionRegistry) Uid() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConversionRegistry ¶
type ConversionRegistry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *ConversionRegistry
NewRegistry creates a new instance of conversion registry.
func (*ConversionRegistry) LinkHandler ¶
func (or *ConversionRegistry) LinkHandler(fh sprout.Handler) error
LinkHandler links the handler to the registry at runtime.
func (*ConversionRegistry) RegisterAliases ¶ added in v0.6.0
func (cr *ConversionRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error
func (*ConversionRegistry) RegisterFunctions ¶
func (cr *ConversionRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
func (*ConversionRegistry) RegisterNotices ¶ added in v0.6.0
func (cr *ConversionRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
func (*ConversionRegistry) ToBool ¶
func (cr *ConversionRegistry) ToBool(v any) (bool, error)
ToBool converts a value to a boolean.
Parameters:
v any - the value to convert to a boolean. This can be any types reasonably be converted to true or false.
Returns:
bool - the boolean representation of the value. error - error if the value cannot be converted to a boolean.
Example:
{{ "true" | toBool }} // Output: true
func (*ConversionRegistry) ToDate ¶
func (cr *ConversionRegistry) ToDate(fmt, str string) (time.Time, error)
ToDate converts a string to a time.Time object based on a format specification.
Parameters:
fmt string - the date format string. str string - the date string to parse.
Returns:
time.Time - the parsed date. error - error if the date string does not conform to the format.
Example:
{{ "2006-01-02", "2023-05-04" | toDate }} // Output: 2023-05-04 00:00:00 +0000 UTC
func (*ConversionRegistry) ToDuration ¶
func (cr *ConversionRegistry) ToDuration(v any) (time.Duration, error)
ToDuration converts a value to a time.Duration.
Parameters:
v any - the value to convert to time.Duration. This value can be a string, int, or another compatible type.
Returns:
time.Duration - the duration representation of the value. error - error if the value cannot be converted to a duration.
Example:
{{ (toDuration "1h30m").Seconds }} // Output: 5400
func (*ConversionRegistry) ToFloat64 ¶
func (cr *ConversionRegistry) ToFloat64(v any) (float64, error)
ToFloat64 converts a value to a float64.
Parameters:
v any - the value to convert to a float64.
Returns:
float64 - the float64 representation of the value. error - error if the value cannot be converted to a float64.
Example:
{{ "123.456" | toFloat64 }} // Output: 123.456
func (*ConversionRegistry) ToInt ¶
func (cr *ConversionRegistry) ToInt(v any) (int, error)
ToInt converts a value to an int using robust type casting.
Parameters:
v any - the value to convert to an int.
Returns:
int - the integer representation of the value. error - error if the value cannot be converted to an int.
Example:
{{ "123" | toInt }} // Output: 123
func (*ConversionRegistry) ToInt64 ¶
func (cr *ConversionRegistry) ToInt64(v any) (int64, error)
ToInt64 converts a value to an int64, accommodating larger integer values.
Parameters:
v any - the value to convert to an int64.
Returns:
int64 - the int64 representation of the value. error - error if the value cannot be converted to an int64.
Example:
{{ "123456789012" | toInt64 }} // Output: 123456789012
func (*ConversionRegistry) ToOctal ¶
func (cr *ConversionRegistry) ToOctal(v any) (int64, error)
ToOctal parses a string value as an octal (base 8) integer.
Parameters:
v any - the string representing an octal number.
Returns:
int64 - the decimal (base 10) representation of the octal value. error - error if the value cannot be converted to an octal number.
Example:
{{ "123" | toOctal }} // Output: 83 (since "123" in octal is 83 in decimal)
func (*ConversionRegistry) ToString ¶
func (cr *ConversionRegistry) ToString(v any) string
ToString converts a value to a string, handling various types effectively.
Parameters:
v any - the value to convert to a string.
Returns:
string - the string representation of the value.
Example:
{{ 123 | toString }} // Output: "123"
func (*ConversionRegistry) ToUint ¶
func (cr *ConversionRegistry) ToUint(v any) (uint, error)
ToUint converts a value to a uint.
Parameters:
v any - the value to convert to uint. This value can be of any type that is numerically convertible.
Returns:
uint - the uint representation of the value. error - error if the value cannot be converted to a uint.
Example:
{{ "123" | toUint }} // Output: 123
func (*ConversionRegistry) ToUint64 ¶
func (cr *ConversionRegistry) ToUint64(v any) (uint64, error)
ToUint64 converts a value to a uint64.
Parameters:
v any - the value to convert to uint64. This value can be of any type that is numerically convertible.
Returns:
uint64 - the uint64 representation of the value. error - error if the value cannot be converted to a uint64.
Example:
{{ "123456789012345" | toUint64 }} // Output: 123456789012345
func (*ConversionRegistry) Uid ¶
func (or *ConversionRegistry) Uid() string
Uid returns the unique identifier of the registry.