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 phantomjs 动态代理实现

phantomjs 是个很优秀的软件,虽然现在被chrome headless 抢了风头,但在某些特定场合,使用phantomjs 还是很方便,这里是介绍使用Go 实现动态代理。...

Golang 生成防识别的图片验证码

验证码 captcha 是对抗密码强力破解、垃圾信息的有效方式,一般用于用户注册、登录,当检测到频繁发帖时也会启用验证码。下面介绍用golang 生成防机器识别的图片验证码。...

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

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