I\'m a newcomer to Go. I extremely like the language, but I quickly realised that I needed to start dividing my files due to an increase in program size.
go r
Finally we can now use:
go run .
thanks to: https://github.com/golang/go/issues/22726#issuecomment-345841019
On Windows I usually just add a little test.bat to all my project directories:
go build
.\{project_name}.exe
go clean
Works well enough. Replace {project_name} with the name of your executable, of course. And once the executable finishes, the batch script moves on to the clean up.
For window the following works: Open cmd and go to the path where your folder exists. Then type the following command and press Enter.
go build
after this one executable will be created. Then in the command prompt call the executable. If your executable name is Project.exe then type the following and press Enter:
Project.exe
If i understand your question right, you need import other code as libraries.
Little example
./testing/main.go:
package main
import "fmt"
import L "testing/lib"
func main() {
fmt.Println("Hello from main()")
L.Somefunc()
}
./testing/lib/somelib.go:
package lib
import "fmt"
func Somefunc() {
fmt.Println("Hello from Somefunc()")
return
}
To launch - go run main.go
You can run all .go
files, excluding tests, using this bash construction:
go run $(ls -1 *.go | grep -v _test.go)