[Go] Define a function

Created on November 30, 2026

Use func followed by the function name, the parameter list, and the return type.

func functionName(parameter ParameterType) ReturnType {
  ...
}

The function greet takes a string parameter named yourname and returns a string.

func greet(yourname string) string {
  return "Hello, " + yourname + "."
}
Go