Skip to content

Latest commit

 

History

History
57 lines (39 loc) · 739 Bytes

functions.md

File metadata and controls

57 lines (39 loc) · 739 Bytes
title
Functions in Go

Functions

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"
}

Calling Functions from other files

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