Functions
The main elements of packages are functions, which are the subject of this section.
Type methods and functions are implemented in the same way and, sometimes, the terms functions and type methods are used interchangeably.
A piece of advice: functions must be as independent of each other as possible and must do one job (and only one job) well. So, if you find yourself writing functions that do multiple things, you might want to consider replacing them with multiple functions instead.
You should already know that all function definitions begin with the func
keyword, followed by the function’s signature and its implementation, and that functions accept none, one, or multiple arguments and return none, one, or multiple values back. The single most popular Go function is main()
, which is used in every executable Go program—the main()
function accepts no parameters and returns nothing, but it is the starting point of every Go program. Additionally...