In this case, because you call the same function, you could also try a helper function:
// GetParameters retrieves multiple parameters using GetParameter. func GetParameters(params ...string) ([]string, error) { var values []string for _, param := range params { value, err := GetParameter(param) if err != nil { return nil, err // alternatively you could also collect & combine all errors } values = append(values, value) } return values, err } params, err := GetParameters("TENANT_ID", "CLIENT_ID", "CLIENT_SECRET") if err != nil { return err } tenantID, clientID, clientSecret := params[0], params[1], params[2] On Wednesday, October 7, 2020 at 8:36:07 PM UTC+2 johan.ma...@dexyos.fr wrote: > Hi, I'm looking for thoughts from some experienced go programmers on a > technique to reduce error handling verbosity. > > The basic idea is to be optimistic over a few instructions, and then > combine many errors in to one. This gist and explains the idea (note the > absence of if err != nil {} ) > > tenantID, err1 := store.GetParameter("TENANT_ID") > clientID, err2 := store.GetParameter("CLIENT_ID") > clientSecret, err3 := store.GetParameter("CLIENT_SECRET") > > globalErr := multierr.Combine(err1, err2, err3) > return connection{ > tenantID, > clientID, > clientSecret, > }, globalErr > > There's some more detail in a post > http://martinsson-johan.blogspot.com/2020/10/less-error-handling-noice-in-go.html. > > I'm sure someone else has already proposed this, but I wasn't able to find > it. Grateful for pointers > > While it seems sound to me I'm a very interested in what people from the > community thinks. > > Cheers > Johan Martinsson > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/18f311c2-8575-4214-b0ae-6a107e16f453n%40googlegroups.com.