Creating a Function in Golang
A declaration begins with the func keyword, followed by the name you want the function to have, a pair of parentheses (), and then a block containing the function's code.
The following example has a function with the name SimpleFunction. It takes no parameter and returns no values.
Example
package main
import "fmt"
// SimpleFunction prints a message
func SimpleFunction() {
fmt.Println("Hello World")
}
func main() {
SimpleFunction()
}
Output
Hello World
Most Helpful This Week
Golang Passing Address to a Function
What is Function in Golang
Simple function with return value in Golang
Higher Order Functions in Golang
The return values of a function can be named in Golang
Anonymous Functions in Golang
Golang Functions Returning Multiple Values
Naming Conventions for Golang Functions
User Defined Function Types in Golang
Simple function with parameters in Golang
Closures Functions in Golang