GolangNote

Golang笔记

golang 引入main 包名下的函数、变量

Permalink

golang 引入main 包名下的函数、变量

Go: 测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ cat main.go 
package main

func main() {
    p()
}
$ cat tst.go 
package main

import "fmt"

func p() {
    fmt.Println("ola")
}
$ go build ./ && ./test 
ola

直接 go run main.go 会提示函数不存在

要进入文件夹运行 go build .

本文网址: https://golangnote.com/topic/155.html 转摘请注明来源

Related articles

Golang Range 的性能提升Tip

Go 语言里使用 range 可以方便遍历数组(array)、切片(slice)、字典(map)和信道(chan)。这里主要关注他们的性能。...

Golang 数据库 Bolt 碎片整理

Bolt 是一个优秀、纯 Go 实现、支持 ACID 事务的嵌入式 Key/Value 数据库。但在使用过程中会有很多空间碎片。一般数据库占用的空间是元数据空间的 1.5~4 倍。Bolt 没有内置的压缩功能,需要手动压缩。...

Golang 时区时差处理方式

个人习惯用 0 时区时间戳记录时间,可以方便转到不同时区,下面介绍 Golang 时区时差处理...

Write a Comment to "golang 引入main 包名下的函数、变量"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.22.3 Processed in 3ms