maps

package
v0.0.0-...-a264c11 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package maps provides utility functions for working with maps and structs. It includes functions for converting between maps and structs, as well as retrieving nested values from maps using dot notation.

This package is particularly useful when dealing with dynamic data structures or when working with configuration data that needs to be converted between different formats.

Key features: - Map2Struct: Converts a map to a struct using reflection - Get: Retrieves nested values from maps using dot notation - Support for weakly typed input when converting maps to structs - Handling of time.Duration conversions from string representations

Usage example:

input := map[string]interface{}{
	"name": "John Doe",
	"age":  30,
	"address": map[string]interface{}{
		"street": "123 Main St",
		"city":   "Anytown",
	},
}

// Retrieve a nested value
city := maps.Get(input, "address.city")

// Convert map to struct
type Person struct {
	Name    string
	Age     int
	Address struct {
		Street string
		City   string
	}
}
var person Person
err := maps.Map2Struct(input, &person)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(dst map[string]any, src map[string]any)

func Get

func Get(input interface{}, fieldName string) interface{}

Get 获取map中的字段,支持嵌套结构获取,例如fieldName.subFieldName.xx 嵌套类型必须是map[string]interface{} 如果字段不存在,返回nil

func Map2Struct

func Map2Struct(input any, output any) error

Map2Struct Decode takes an input structure and uses reflection to translate it to the output structure. output must be a pointer to a map or struct.

func Struct2Map

func Struct2Map(input any, output any)

Types

This section is empty.

Jump to

Keyboard shortcuts

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