greflect

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

反射工具包

工具加载

import (
	"github.com/cnlesscode/gotool/greflect"
)

GetType(structPoint interface{}) string

函数功能 : 获取变量类型 返回格式 : string

var str string = "abc"
func main() {
	stName := greflect.GetType(str)
	fmt.Printf("%v\n", stName)
}

GetStructName(structPoint interface{}) string

函数功能 : 获取变量对应结构体名称 返回格式 : string

type TestStruct struct {
	Id   int
	Name string 
}

func main() {
	stName := greflect.GetStructName(TestStruct{})
	fmt.Printf("stName: %v\n", stName)
}

PrintStructVars(structPoint interface{})

函数功能 : 打印结构体变量

type TestStruct struct {
	Id   int    `gorm:"id;primaryKey"`
	Name string `gorm:"name"`
}

func main() {
	greflect.PrintStructVars(&TestStruct{Id: 1, Name: "test"})
}

PrintStructVars(structPoint interface{})

函数功能 : 打印结构体变量

type TestStruct struct {
	Id   int    `gorm:"id;primaryKey"`
	Name string `gorm:"name"`
}

func main() {
	greflect.PrintStructVars(&TestStruct{Id: 1, Name: "test"})
}

PrintStructMethods(structPoint interface{})

函数功能 : 打印结构体方法

type TestStruct struct {
	Id   int    `gorm:"id;primaryKey"`
	Name string `gorm:"name"`
}

func (st TestStruct) Say() {
	println("say ..." + st.Name)
}

func main() {
	st := &TestStruct{}
	greflect.PrintStructMethods(st)
}

PrintStructTags(structPoint interface{})

函数功能 : 打印结构体标签

type TestStruct struct {
	Id   int    `gorm:"id;primaryKey"`
	Name string `gorm:"name"`
}

func main() {
	st := TestStruct{}
	greflect.PrintStructTags(&st)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStructName

func GetStructName(structPoint interface{}) string

获取结构体名称

func GetType

func GetType(structPoint interface{}) string

获取变量类型

func PrimaryKeyValue

func PrimaryKeyValue(structPoint interface{}, PrimaryKey string) int

获取数据主键值

func PrintStructMethods

func PrintStructMethods(structPoint interface{})

打印结构体方法

func PrintStructTags

func PrintStructTags(structPoint interface{})

打印结构体标签

func PrintStructVars

func PrintStructVars(structPoint interface{})

打印结构体变量

Types

This section is empty.

Jump to

Keyboard shortcuts

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