I want to call function from another file in Go. Can any one help?
test1.go
package main
func main() {
demo()
}
test2.go
package main
import "fmt"
func main() {
}
func demo() {
fmt.Println("HI")
}
How to call demo in test2 from test1?
You can’t have more than one
mainin your package.More generally, you can’t have more than one function with a given name in a package.
Remove the
mainintest2.goand compile the application. Thedemofunction will be visible fromtest1.go.