Golang functions

From wikinotes
Revision as of 20:55, 23 May 2022 by Will (talk | contribs)
//        (param  type) (return-type)
func greet(name string) string {
    return "Hello, " + name
}

Multiple return values

// when multiple return values present, surround with brackets
func find(id int) (string, int) {
    // ...
}

// optionally, return values can be named
// (this has no implications for caller, it's simply documentation)
func find(id int) (name string, age int) {
    // ...
}