transform

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

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelToSnake

func CamelToSnake(s string) string

CamelToSnake 驼峰转蛇形

func SnakeToCamel

func SnakeToCamel(s string) string

SnakeToCamel 蛇形转驼峰

func ToMap

func ToMap(input interface{}) (map[string]interface{}, error)

ToMap 将结构体转换为 map(使用默认转换器)

func ToStruct

func ToStruct(input map[string]interface{}, output interface{}) error

ToStruct 将 map 转换为结构体(使用默认转换器)

func Transform

func Transform(input, output interface{}) error

Transform 通用转换(使用默认转换器)

Types

type Converter

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

Converter 结构体转换器

func NewConverter

func NewConverter() *Converter

NewConverter 创建新的转换器

func (*Converter) Convert

func (c *Converter) Convert(input, output interface{}) error

Convert 通用转换方法,支持任意类型到任意类型

func (*Converter) ConvertSlice

func (c *Converter) ConvertSlice(inputSlice interface{}, outputSlice interface{}) error

ConvertSlice 转换切片

func (*Converter) MapToStruct

func (c *Converter) MapToStruct(input map[string]interface{}, output interface{}) error

MapToStruct 将 map 转换为结构体

func (*Converter) MustConvert

func (c *Converter) MustConvert(input, output interface{})

MustConvert 安全转换,如果出错会 panic

func (*Converter) StructToMap

func (c *Converter) StructToMap(input interface{}) (map[string]interface{}, error)

StructToMap 将结构体转换为 map(支持嵌套结构体)

func (*Converter) WithDecodeHook

func (c *Converter) WithDecodeHook(hook mapstructure.DecodeHookFunc) *Converter

WithDecodeHook 添加自定义解码钩子

func (*Converter) WithTagName

func (c *Converter) WithTagName(tagName string) *Converter

WithTagName 设置自定义标签名

func (*Converter) WithWeaklyTyped

func (c *Converter) WithWeaklyTyped(enable bool) *Converter

WithWeaklyTyped 设置弱类型转换

Jump to

Keyboard shortcuts

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