MaybeUnwrap returns nil if len(errs) is 0. It returns the first and only contained error as error if len(errs is 1). In all other cases, it returns the MultiError directly. This is helpful for returning a MultiError in a way that only uses the MultiError if needed.
()
| 240 | // the MultiError directly. This is helpful for returning a MultiError in a way |
| 241 | // that only uses the MultiError if needed. |
| 242 | func (errs MultiError) MaybeUnwrap() error { |
| 243 | switch len(errs) { |
| 244 | case 0: |
| 245 | return nil |
| 246 | case 1: |
| 247 | return errs[0] |
| 248 | default: |
| 249 | return errs |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // Registry registers Prometheus collectors, collects their metrics, and gathers |
| 254 | // them into MetricFamilies for exposition. It implements Registerer, Gatherer, |