Why this matters
Prevents divergence of business rules and reduces maintenance cost.
Centralize repeated validation rules into helpers or small packages. Reuse them across handlers, services, and jobs.
Prevents divergence of business rules and reduces maintenance cost.
Side-by-side examples engineers can pattern-match during review.
if amount <= 0 { return fmt.Errorf("amount <= 0") }
// repeated in many placesfunc validateAmount(v int) error {
if v <= 0 { return errors.New("amount_must_be_positive") }
return nil
}
// reuse validateAmount(...) everywhere// copy-paste the same checks in multiple filesfunc validateX(...) error { ... } // reusedFrom the same buckets as this rule.