beans

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyProperties

func CopyProperties(src interface{}, target interface{}) error

CopyProperties copy the source structure data to the target structure.

src: source structure, type can be pointer and normal.
target: target structure, type must be a pointer.

Example:

type Src struct {
   Gender   int                  // The name of the field is used when not specified
   Age      int    `copy:"Age"`  // Specify field name
   Username string `copy:"-"`    // Ignore the copy by setting "-", or make the field private
}

type Target struct {
   Age      int
   Username string
   Gender   int
}

err := Beans.CopyProperties(&src, &target)

func ToMap

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

ToMap structure to map.

Notes: Non-public fields are not processed

Example:

   type User struct {
       Username string             // the filed name is used as the key
       UserAge  int `alias:"年龄"`  // replace the field name with an alias
   }

   beans.ToMap(&user)

Types

This section is empty.

Jump to

Keyboard shortcuts

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