英文:
how to invoke a function the package which was not be imported in golang
问题
如何在 golang 中调用一个未导入的包中的函数
mypkg.go
package mypkg
import "fmt"
func Test(){
    fmt.Println("test")
}
main.go
package main
func main(){
    // 我没有导入包 "mypkg"
    // 如何调用包 "mypkg" 中名为 Test() 的函数
}
我需要你的帮助,谢谢。
英文:
how to invoke a function the package which was not be imported in golang
mypkg.go
package mypkg
import "fmt"
func Test(){
    fmt.Println("test")
}
main.go
package main
func main(){
    // I didn't import the package "mypkg"
    // How to invoke the function named Test() of package "mypkg"
}
I need you help,thanks.
答案1
得分: 4
你需要导入这个包,没有其他的方法:
package main
import "mypkg"
func main() {
    mypkg.Test()
}
英文:
You need to import the package, there is no way arround:
package main
import "mypkg"
func main(){
    mypkg.Test()
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论