Lawrence Gimenez

Build Go programs with GitHub modules present

I was hit with an error when I try to run a Go script, go run somescript.go. This is a note to my future self, in case I totally forgot.

no required module provides package github.com/gofrs/uuid: go.mod file not found in current directory or any parent directory; see 'go help modules'

I need to run the command below.

go mod init somescript.go

Then it will output the following lines.

go: creating new go.mod: module somescript.go
go: to add module requirements and sums:
	go mod tidy

Then run mod tidy.

go mod tidy

And the output will be.

go: finding module for package github.com/gofrs/uuid
go: downloading github.com/gofrs/uuid v4.4.0+incompatible
go: found github.com/gofrs/uuid in github.com/gofrs/uuid v4.4.0+incompatible

Then build it.

go build somescript.go

It will create the following files

ls
go.mod		go.sum		somescript	 somescript.go

Run the compiled script.

./somescript