How to discover all package types at runtime?

后端 未结 5 1527
醉酒成梦
醉酒成梦 2020-12-14 02:55

As far as I\'m aware (see here, and here) there is no type discovery mechanism in the reflect package, which expects that you already have an instance of the type or value y

5条回答
  •  孤街浪徒
    2020-12-14 03:44

    Thanks @thwd and @icio, follow your direction it still worked on 1.13.6 today.

    Follow your way the tl.s will be:

    TEXT ·typelinks(SB), $0-0
        JMP reflect·typelinks(SB)
    

    yes, no package name and no "add" function in it.

    then follow @icio's way change "add" function to:

    func add(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer {
        return unsafe.Pointer(uintptr(p) + x)
    }
    

    then all worked now. :)

提交回复
热议问题