tostring

package
v0.0.0-...-8a86631 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package tostring provides functionality to convert arbitrary Go values into their string representation, while also detecting NULL or zero-equivalent values. It is primarily used for consistent string serialization in data export scenarios.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type String

type String struct {
	String string
	IsNULL bool
}

String represents a string value along with a flag indicating whether it was NULL. If IsNULL is true, then the value should be considered as NULL or absent.

func ToString

func ToString(v any) String

ToString converts an arbitrary value to a String type, which contains a string representation of the value and a flag indicating if the value was NULL.

The conversion logic supports common Go primitive types, slices, time.Time, and types implementing json.Marshaler or fmt.Stringer interfaces.

If the input is nil or represents an empty/null value (like zero time, "null", "[]", or "{}" in JSON), the result will have IsNULL set to true.

Jump to

Keyboard shortcuts

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