Functions

Functions are the main way that anything is computed in Go.

This is a function:

func addInt(a, b int) int { return a + b }

We call func addInt(a, b int) int, which is the function signature. The function signature is composed of the function name, parameters, and return type(s).

The name of the function is addInt. Note the formatting being used. The function name is in camelCase—this is the preferred casing of names in Go. The first letter of any name, when capitalized, like AddInt indicates that it should be exported. By and large in this book we shan't worry about exported or unexported names, as we will be mostly using functions. But if you are writing a package, then it matters. Exported names are available from outside a package. ...

Get Go Machine Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.