reflect 反射间单间例子

package main

import (
    "fmt"
    "reflect"
)

type services []int

type name struct {
    Name *string `json:"name" orm:"column(ok)"`
}
func main() {
    j := "asd"
    a := name{&j}
    valA := reflect.ValueOf(a)
    fmt.Println(valA)
    kind := valA.Kind()
    fmt.Println(kind)
    valid := valA.IsValid()
    fmt.Println(valid)
    test := reflect.Indirect(valA)
    fmt.Println(test)
    elem := test.FieldByName("Name").Elem()
    fmt.Println(elem)
    fmt.Println("-----------------")
    of := reflect.TypeOf(a)
    fmt.Println(of)
    fmt.Println(of.Kind())
    fmt.Println(of.FieldByName("Name"))
    fmt.Println(of.Name())
    fmt.Println(of.Field(0).Tag.Get("json"))
}

----------------------------------------------------------
结果:
{0xc000010200}
struct
true
{0xc000010200}
asd
-----------------
main.name
struct
{Name  *string json:"name" orm:"column(ok)" 0 [0] false} true
name
name

 

posted @ 2021-07-20 16:05  Black_Climber  阅读(35)  评论(0编辑  收藏  举报