value

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Overview

Package value provides utilities for type casting and copying values using reflection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cast

func Cast[T any](in any) (t T)

Cast performs a type assertion to convert an interface{} value to a specific type T. Returns the zero value of type T if the conversion fails. This is a generic function that provides safe type casting.

func Copy

func Copy(from interface{}, to interface{})

Copy performs a deep copy of values from the source to the destination using reflection. It handles primitive types, structs, and maps with type compatibility checking. Both from and to parameters can be pointers or values. The function only copies fields with matching names and compatible types. Optimized version with reduced reflection overhead and early type checking.

func JsonMarshal

func JsonMarshal(obj interface{}) string

JsonMarshal converts an object to its JSON string representation. Returns an empty string if the marshaling fails. This provides a safe way to convert objects to JSON without handling errors explicitly. Optimized version with early type checking and reduced allocations.

Types

This section is empty.

Jump to

Keyboard shortcuts

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