vconv

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int

func Int(any any) int

Int converts `any` to int.

func Int64

func Int64(any any) int64

Int64 converts `any` to int64.

func Map

func Map(value any, tags ...MapOption) map[string]any

Map converts any variable `value` to map[string]any. If the parameter `value` is not a map/struct/*struct type, then the conversion will fail and returns nil.

If `value` is a struct/*struct object, the second parameter `priorityTagAndFieldName` specifies the most priority priorityTagAndFieldName that will be detected, otherwise it detects the priorityTagAndFieldName in order of: gconv, json, field name.

func String

func String(any any) string

String converts `any` to string. It's most commonly used converting function.

func Struct

func Struct(params any, pointer any, mapping ...map[string]string) (err error)

Struct maps the params key-value pairs to the corresponding struct object's attributes. The third parameter `mapping` is unnecessary, indicating the mapping rules between the custom key name and the attribute name(case-sensitive).

Note:

  1. The `params` can be any type of map/struct, usually a map.
  2. The `pointer` should be type of *struct/**struct, which is a pointer to struct object or struct pointer.
  3. Only the public attributes of struct object can be mapped.
  4. If `params` is a map, the key of the map `params` can be lowercase. It will automatically convert the first letter of the key to uppercase in mapping procedure to do the matching. It ignores the map key, if it does not match.

Types

type MapOption

type MapOption = gconv.MapOption

Jump to

Keyboard shortcuts

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