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.
1
|
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.
1
|
go mod init somescript.go
|
Then it will output the following lines.
1
2
3
|
go: creating new go.mod: module somescript.go
go: to add module requirements and sums:
go mod tidy
|
Then run mod tidy.
And the output will be.
1
2
3
|
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.
It will create the following files
1
2
|
ls
go.mod go.sum somescript somescript.go
|
Run the compiled script.