maps

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool

func GetBool(dict map[string]any, key string) bool

以布尔形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。

出参:

  • 字典中键对应的值。如果指定键不存在或者值的类型不是布尔,则返回 false。

func GetInt added in v0.4.4

func GetInt(dict map[string]any, key string) int

以整数形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。

出参:

  • 字典中键对应的值。如果指定键不存在或者值的类型不是整数,则返回 0。

func GetInt32

func GetInt32(dict map[string]any, key string) int32

以 32 位整数形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。

出参:

  • 字典中键对应的值。如果指定键不存在或者值的类型不是 32 位整数,则返回 0。

func GetInt64

func GetInt64(dict map[string]any, key string) int64

以 64 位整数形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。

出参:

  • 字典中键对应的值。如果指定键不存在或者值的类型不是 64 位整数,则返回 0。

func GetKVMap

func GetKVMap[V any](dict map[string]any, key string) map[string]V

以 `map[string]V` 形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。

出参:

  • 字典中键对应的 `map[string]V` 对象。

func GetKVMapAny

func GetKVMapAny(dict map[string]any, key string) map[string]any

以 `map[string]any` 形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。

出参:

  • 字典中键对应的 `map[string]any` 对象。

func GetOrDefaultBool

func GetOrDefaultBool(dict map[string]any, key string, defaultValue bool) bool

以布尔形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。
  • defaultValue: 默认值。

出参:

  • 字典中键对应的值。如果指定键不存在或者值的类型不是布尔,则返回默认值。

func GetOrDefaultInt added in v0.4.4

func GetOrDefaultInt(dict map[string]any, key string, defaultValue int) int

以整数形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。
  • defaultValue: 默认值。

出参:

  • 字典中键对应的值。如果指定键不存在、值的类型不是整数或者值为零值,则返回默认值。

func GetOrDefaultInt32

func GetOrDefaultInt32(dict map[string]any, key string, defaultValue int32) int32

以 32 位整数形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。
  • defaultValue: 默认值。

出参:

  • 字典中键对应的值。如果指定键不存在、值的类型不是 32 位整数或者值为零值,则返回默认值。

func GetOrDefaultInt64

func GetOrDefaultInt64(dict map[string]any, key string, defaultValue int64) int64

以 64 位整数形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。
  • defaultValue: 默认值。

出参:

  • 字典中键对应的值。如果指定键不存在、值的类型不是 64 位整数或者值为零值,则返回默认值。

func GetOrDefaultString

func GetOrDefaultString(dict map[string]any, key string, defaultValue string) string

以字符串形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。
  • defaultValue: 默认值。

出参:

  • 字典中键对应的值。如果指定键不存在、值的类型不是字符串或者值为零值,则返回默认值。

func GetString

func GetString(dict map[string]any, key string) string

以字符串形式从字典中获取指定键的值。

入参:

  • dict: 字典。
  • key: 键。

出参:

  • 字典中键对应的值。如果指定键不存在或者值的类型不是字符串,则返回空字符串。

func Populate

func Populate(dict map[string]any, output any) error

将字典填充到指定类型的结构体。 与 [json.Unmarshal] 类似,但传入的是一个 [map[string]any] 对象而非 JSON 格式的字符串。

入参:

  • dict: 字典。
  • output: 结构体指针。

出参:

  • 错误信息。如果填充失败,则返回错误信息。

Types

This section is empty.

Jump to

Keyboard shortcuts

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