We changed our privacy policy. Read more.

New answers tagged


A couple of things: If you are not returning any rich data in your errors (beyond an extra error string), then a custom error may be overkill. One can achieve the same with: if errors.Is(err, NotFound) { return fmt.Errorf("Business Logic Error: %w", err) } fmt.Errorf with the %w wrap-verb wraps a new error with the added error message - ...


Using your algorithm, there's some memory management tweaks to improve performance: map[int]bool can be replaced by map[int]struct{} - since only map-key lookup is needed to detect a duplicate if you know the output size of a slice before hand, you can pre-allocate the exact size and place values precisely in their various indices - avoiding reallocs with ...

Top 50 recent answers are included