package main import ( "fmt" "os" ) func main() { fmt.Println(os.Executable()) fmt.Println(os.Getwd()) }
zzh@ZZHPC:~/zd/Github/ztest$ go run main.go /tmp/go-build2963213184/b001/exe/main <nil> /home/zzh/zd/Github/ztest <nil>
zzh@ZZHPC:~/zd/Github/ztest$ tree . ├── config │ └── config.go ├── go.mod └── main.go 1 directory, 3 files
package config import ( "fmt" "os" ) func LoadConfig() { fmt.Println(os.Executable()) wd, _ := os.Getwd() fmt.Printf("current directory: %s", wd + "/config") }
package main import ( "ztest/config" ) func main() { config.LoadConfig() }
zzh@ZZHPC:~/zd/Github/ztest$ go run main.go /tmp/go-build3485574147/b001/exe/main <nil> current directory: /home/zzh/zd/Github/ztest/config
标签:Get,os,fmt,ztest,current,source,go,main,config From: https://www.cnblogs.com/zhangzhihui/p/18556539