0

Go – Return multiple values from a Function

In Go (or Golang), it is possible to return more than one value from a function.

Function Declaration

I’ve never seen or used something like it before but I think the multi-value-return is great. Most programming language has similar facility that support only single return value.

The general syntax of functions is Go is as follows.

We have the func keyword that indicates MyFunction is a function. It has a list of parameters, and a list of result values.

Go Codes

The codes below demonstrates his built-in facility.  Here we have the GetDomainDetails function that returns two (2) values of string type.

The use of “:=” is meant for locally-scoped variables, e.g., function local, variables.

The order of the variables that receive the values matter.

It outputs

Download the codes

https://github.com/Turreta/Golang/tree/master/Return%20multiple%20values%20from%20function