[go-nuts] Re: Reduced error handling noice

2020-10-09 Thread Markus Heukelom
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)

[go-nuts] Re: Reduced error handling noice

2020-10-08 Thread Johan Martinsson
Indeed I learned this from https://blog.golang.org/defer-panic-and-recover and they mention this is done in the json module. And I couldn't adhere more. It's basically the same as try-catch from other languages. Doing this systematically in a Rest server for errors of type 502, 400, 404 (in t

[go-nuts] Re: Reduced error handling noice

2020-10-07 Thread David Skinner
This looks like something I might have done. However, my preference would be to write a wrapper MustGetParameter receives string field, calls store.GetParameter(field), returns parameter or panics. You may then use defer func() { globalErr = recover()} tenantID, err1 := MustGetParamete