Go FunctionsFunctions are "self contained" modules of code that accomplish a specific task. Functions usually "take in" data, process it, and "return" a result. Once a function is written, it can be used over and over and over again. Functions can be "called" from the inside of other functions.
Functions will not be called automatically once an application starts or load.
In Go, functions are written in a specific way:
- You will need to use the keyword func To define a function in Go.
- It has to have a name followed by open and closing parentheses.
- The set of code to be executed by the function should be surrounded by open and closed braces.
- Functions names must start with a letter only.
- Functions names can only contain alpha-numeric and underscores(A-z, 0-9 and _).
- Functions Names are case sensitive meaning you have to use the same name in uppercase or lowercase.
Go Function creation Syntax
Example of Go Function
In this page (written and validated by A. Gawali) you learned about Go Functions . What's Next? If you are interested in completing Go tutorial, your next topic will be learning about: Go Function Parameters and arguments.
Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: email@example.com.