Initialise GO Project and Import Packages
Written on by Byorn John De Silva.
[ Tip: Easy way to update your Go version in MacOs > brew install go ]
-
Initialise Go project
go mod init github.com/byorn/go-helloworld
-
Add the dependency by importing it directly in your code
in main.go and func main method
import ( "fmt" "github.com/byorn/go-helloworld/util" util2 "github.com/byorn/test-go-modules/util" ) func main(){ fmt.Println(util2.ThisIsSomeMethodToBeCalledFromAnotherRepository())
you might get the below error:
-
you should download the dependant package
> go get github.com.byorn/test-go-modules > go mod tidy
finally run the main file
> go run main.go