gref

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 5 Imported by: 0

README

gref

gref is a utility library in Golang that utilizes reflection for data assignment. The main function is to assign values between two parameters, such as two different structs.

Installation
go get github.com/zy1024/gref
Document Language : English, 中文.

Features

1. Copy

The Copy(src,dst) function requires two pointers, such as pointers to structs or slices. It will use reflection to assign the value of src to dst. The assignment of structs is based on matching field names, and only non-empty fields in dst will be assigned.

Example

The sample code can be seen in the TestCopy method in example_test.go.

Version

1.3.0

Official release, supporting assignment operations for structs, pointers, slices, and basic data types.

Next Development Steps
  1. Add support for other types, such as channels.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(src, dst interface{}) error

Copy Assignment of two different types, from src to dst Notice: src and dst must be pointers.

func GenerateUpdateFields

func GenerateUpdateFields(req interface{}) (map[string]interface{}, error)

GenerateUpdateFields generates a map of fields to update based on the provided request object. Notice : This req must be pointers to structs It only includes fields that are not zero values and are exported (i.e., start with an uppercase letter). The field names are converted from camelCase to snake_case for use in the database. example: dataBase : {"name": "John", "age": 30} req : {"Age": 31} return : {"age": 31} gorm ues Updates func will update the age field to 31

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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