title |
---|
Functions in Go |
Since Go is a compiled language, we can write the function that should be executed, after the calling function. No problem.
func main() {
greet()
}
func greet() {}
For the return-statement, we MUST define a datatype.
func greet() string {
return "Hi max"
}
main.go:
package main
import "fmt"
func main() {
greet()
}
person.go:
package main
import "fmt"
func greet() {
fmt.Println("Hey Max")
}
Both need to have the package main. The trick is now, to run both files, leading to main.go can access what is inside of person.go
go run main.go person.go
go build main.go person.go