Use early returns to reduce nesting:
func process(data []byte) error {
if len(data) == 0 {
return errors.New("empty data")
}
if !isValid(data) {
return errors.New("invalid data")
}
// Process data
return nil
}
Each check returns if it fails. The main logic stays unindented. This is easier to read than nested if-else.