How does golang see what methods and properties are under an object?

for example, I just started golang to import a third-party package, and then returned to generate an object. The object println says it is a map, but I can"t get out the key, under map, so I want to see what properties and methods are available under this map. I checked the source code, but I didn"t find it. I hereby ask for help

Dec.15,2021

type User struct {
    Name string
}

func (u *User) A() {
    fmt.Println("hello")
}
func (u *User) B(name string) {
    fmt.Printf("Shake hand with %s\n", name)
}

func TestReflect(t *testing.T) {
    u := &User{Name: "xxxx"}
    value := reflect.ValueOf(u)
    typ := value.Type()
    for i := 0; i < value.NumMethod(); iPP {
        fmt.Println(fmt.Sprintf("method[%d]%s and type is %v", i, typ.Method(i).Name, typ.Method(i).Type))
    }
}

use reflect to get what you want. Give it a try.
take a good look at the documentation.

Menu