How to run a Go project with multiple files in the same main package?
Hi! I just started learning Go and ran into a problem. I have a small project consisting of several files, all located in the `cmd` folder and declared as `package main`. Here is the structure:
```
myproject/
cmd/
main.go
helpers.go
config.go
```
In `main.go` I call functions from `helpers.go`, for example:
```go
// main.go
package main
func main() {
msg := getMessage()
fmt.Println(msg)
}
```
```go
// helpers.go
package main
func getMessage() string {
return "Hello from helpers!"
}
```
When I try to run the project with the command `go run cmd/main.go`, I get an error:
```
# command-line-arguments
./main.go:6:14: undefined: getMessage
```
I understand that Go only sees one file. How do I properly run the project so that all files are included?
No answers yet.
Log in to leave an answer