my directory set up is like below
.
├── go.mod
├── main.go
└── urlshort
└── urlshort.go
go.mod
module fromscratch_urlshort
go 1.22.3
root dir name is fromscratch_urlshort, I did
go mod init fromscratch_urlshort
top of urlshort.go is
package urlshort
in main.go
I do
import(
"urlshort"
)
when I run code I got error saying
go run main.go main.go:6:2: package urlshort is not in std (/usr/local/go/src/urlshort)
What am I doing wrong here ? My objective is to import the local module urlshort in main.go
P.S. What is a good way to set up go module when pulling a go project from a repo say github ? would the pulled directory work with go mod init ? what needs to be done ?
go.mod, so how to start with setting the module up ...go.modit is not a complete go project and you’ll have to fix whatever is missing. Set things up just like you would any other project, following the official docs.