Go Function call from another file
- Create
go.mod
file in greetings foldergo mod init ughosh/greetings
- [Note] you can put any name here. Go suggest to make it like a folder structure
- Create greetings.go file
- copy the file. It's just a sample file for reference
- Create
go.mod
file in greetings foldergo mod init ughosh/hello
- Create hello.go file
-
Notice that we've used -
"ughosh/greetings"
as animport
to importgreetings.go
-
Run in Hello folder
go mod edit -replace="ughosh/greetings"=../greetings
go mod tidy
go run .
// this will run your program succesfully!!