A simple Go module with a SayHello
function to print greetings.
Create a go.mod file in your project
go mod init testproject
Use go get
to install the module:
go get github.com/neelkumar01/testmodule
This will download the module and add it to your project dependencies and you will be able to see 2 files, go.mod
and go.sum
being created in your project.
Import the module in your Go code:
package main
import (
"github.com/neelkumar01/testmodule"
)
func main() {
testmodule.SayHello("Neel")
}
Hello Neel
testmodule/
βββ code.go
βββ go.mod