parseutil

package
v2.0.0-alpha.33 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolFrom

func BoolFrom(value interface{}) (bool, bool)

BoolFrom attempts to convert a value to a boolean.

It returns (result, true) on success, or (false, false) if it fails.

Conversion rules:

  • If the value is already a bool, it returns it directly
  • If the value can be converted to a string and parsed by ParseBool, the parsed result is returned
  • Otherwise, it returns (false, false)

func BoolPtrFrom

func BoolPtrFrom(value interface{}) (*bool, bool)

BoolPtrFrom attempts to convert a value to a boolean pointer.

It returns (pointer, true) on success, or (nil, false) if it fails. This is a convenience function wrapping BoolFrom.

Example:

BoolPtrFrom(true)      // (pointer to true, true)
BoolPtrFrom("yes")     // (pointer to true, true)
BoolPtrFrom("invalid") // (nil, false)

func ParseBool

func ParseBool(input string) (bool, error)

ParseBool parses a string representation of a boolean value.

It accepts the following inputs (case-insensitive, whitespace trimmed):

  • Custom values: "yes", "y" (true), "no", "n" (false)
  • Standard values: "true", "t", "1" (true), "false", "f", "0" (false)

Returns an error if the input is empty or cannot be parsed as a boolean.

func StringFrom

func StringFrom(value interface{}) string

StringFrom converts any value to its string representation.

If the value is already a string, it returns it directly for efficiency. Otherwise, it uses fmt.Sprintf with the %v verb to convert the value.

This function always returns a string and never returns an error.

Example:

StringFrom("hello")    // "hello"
StringFrom(42)         // "42"
StringFrom(true)       // "true"
StringFrom(3.14)       // "3.14"

func StringPtrFrom

func StringPtrFrom(value interface{}) *string

StringPtrFrom converts any value to its string representation and returns a pointer.

This is a convenience function that calls StringFrom and returns a pointer to the result.

Example:

StringPtrFrom(42)      // pointer to "42"
StringPtrFrom("test")  // pointer to "test"

Types

This section is empty.

Jump to

Keyboard shortcuts

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