golang如何调用未导出的包函数

How to call an unexported package function, for example package function hello() is defined as:

package testlib

import "fmt"

func hello() {
    fmt.Println("Hello testlib")
}

And there is calling from main package:

package main

import (
  _ "reflect"

    "testlib"
)

func main() {
    testlib.hello()
}

And of course, this program is incorrect. I have googled much, many people mentioned that reflect package could be used to invoke an unexported function, like:

obj := ... (some object)
val := reflect.ValueOf(obj);
fun := val.MethodByName("hello")
fun.Call([]reflect.Value{})

But all examples are based on an object (i.e,. a struct), not a package. My problem is that I am going to call a package function, not an object function. thanks.

You can't. That's the purpose of unexported functions. Only the declaring package can call it.

If you're the package writer, and you need to call it from other packages, then export it. If it's not your package, then don't try to call it. It's not part of the packgage's API, it's an implementation detail and as such it may change at any time (what it does may change, its signature may change, it may get renamed or it might get completely removed at any time).