How to import local packages in Go without GOPATH (Go modules)
Hello! I'm starting to learn Go and I'm having trouble importing local packages. I'm used to working with other languages where you can just create files in one folder and import them. But in Go it turned out to be more complicated.
I have this project structure:
```
myproject/
├── main.go
└── utils/
└── helper.go
```
In `helper.go` I defined a `Hello()` function:
```go
package utils
func Hello() string {
return "Hello from utils!"
}
```
In `main.go` I'm trying to import this package:
```go
package main
import (
"fmt"
"myproject/utils"
)
func main() {
fmt.Println(utils.Hello())
}
```
But when I run `go run main.go`, I get an error: `package myproject/utils is not in GOROOT (/usr/local/go/src/myproject/utils)`. I read that previously
No answers yet.
Log in to leave an answer