duanjiagu0655 2015-10-12 08:29
浏览 369

在Go中编写全局函数-类似于append()

The Question is simple - how can i implement a package independent global function in golang.

ID, if i have a function in an package called core then from another package i need core.Function() to call that function. But i In go implementation there are some functions like - make(), append() for slice that can used without any import and within any package directly. If i wanted to write function like this what is the way of doing this? how can i write any function like this if it is possible.

  • 写回答

2条回答 默认 最新

  • doulubashang6936 2015-10-12 09:34
    关注

    It's not possible to do exactly what you want but you can get somewhat close to it by using a dot-import. E.g. if you dot-import the fmt package, you can spell fmt.Println as just Println:

    package main
    
    import . "fmt"
    
    func main() {
        Println("Hello, playground")
    }
    

    Playground: http://play.golang.org/p/--dWV6PHYA.

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计