Answer the question
In order to leave comments, you need to log in
How to split a GO project into separate files, and then include them in main?
I don't want to write the path to my local packages through the github repository.
There is a project broken into files in different folders.
How to include them in main?
On import swears.
Answer the question
In order to leave comments, you need to log in
You can do it through `go mod`, something like this:
1. Create a folder yourproject.com/ wherever you like
2. cd yourproject.com/ ; go mod init yourproject.com
3. Create the pkg1 package inside yourproject.com, i.e. yourproject.com/pkg1
4. Create main.go
5. Run the command go run .
Project structure
yourproject.com/main.go
yourproject.com/go.mod (появится после выполнения команды go mod init)
yourproject.com/pkg1/pkg1.go
package main
import "yourproject.com/pkg1"
func main() {
pkg1.SomeFunc()
}
package pkg1
import "fmt"
func SomeFunc() {
fmt.Println(`SomeFunc called`)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question