I'm trying to understand Go modules and create a simple hello world program. Go version: 1.16.2
/project1
/project1/main.go
/project1/helpers/helpers.go
helpers.go
will contain some utility method like:
package ???
import "fmt"
func DoSomething() {
fmt.Println("Doing something in helpers.go")
}
main.go
will use methods from helpers.go
like this:
package main
import "??"
func main() {
helpers.DoSomething()
}
VSCode is not allowing me to do this and has a red underline on helpers
.
What am I missing here? How can I achieve this?
Edit 1: Adding go.mod and package names:
So I ran go mod init helpers
in /helpers
folder and came out with this:
/project1/helpers/helpers.go
/project1/helpers/go.mod
go.mod
module helpers
go 1.16
My main.go
now looks like this:
package main
import (
"fmt"
"helpers"
)
func main() {
fmt.Println("blah")
helpers.DoHelperMethod()
}