conv

package
v0.8.0 Latest Latest
Warning

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

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

Documentation

Overview

Package conv provides a configurable, reflection-based type converter. It supports primitives, slices, maps, structs, pointer cloning, time parsing, and custom conversion functions registered per source/destination type.

Index

Constants

View Source
const DefaultDateLayout = "2006-01-02 15:04:05.000"

DefaultDateLayout is the default layout used for time parsing when no layout is specified

Variables

This section is empty.

Functions

This section is empty.

Types

type ConversionFunc

type ConversionFunc func(src interface{}, dest interface{}, opts Options) error

ConversionFunc defines a custom conversion function

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

Converter provides type conversion functionality

func NewConverter

func NewConverter(options Options) *Converter

NewConverter creates a new type converter with the provided options

func (*Converter) Convert

func (c *Converter) Convert(src interface{}, dest interface{}) error

Convert converts the source value to the destination value Changed signature to take destination as second parameter

func (*Converter) RegisterConversion

func (c *Converter) RegisterConversion(srcType, destType reflect.Type, fn ConversionFunc)

RegisterConversion registers a custom conversion function between source and destination types

type Options

type Options struct {
	// DateLayout specifies the layout for time parsing
	DateLayout string
	// TagName is the struct tag name to look for mapping information
	TagName string
	// CaseSensitive controls whether field/key matching is case sensitive
	CaseSensitive bool
	// IgnoreUnmapped controls whether to ignore unmapped fields
	IgnoreUnmapped bool
	// ClonePointerData if true, creates a clone of data pointed by pointers
	ClonePointerData bool
	// AccessUnexported if true, allows accessing unexported fields
	AccessUnexported bool
}

Options contains configuration for the converter

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns default conversion options

Jump to

Keyboard shortcuts

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