Created
August 30, 2018 15:42
-
-
Save pdk/4edcf95359f4b4ce13574c411e58247c to your computer and use it in GitHub Desktop.
naive refactor of non-error checking in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GatherItems collects incoming items. If somehow we get more than n, an error is returned. | |
func GatherItems(n int) ([]string, error) { | |
checkLen := func() { | |
if len(items) > n { | |
return items, fmt.Errorf("more than %d items gathered: %d", n, len(items)) | |
} | |
} | |
var items []string | |
items = append(items, GetItemsFromSourceAlpha()...) | |
checkLen() | |
items = append(items, GetItemsFromSourceBeta()...) | |
checkLen() | |
items = append(items, GetItemsFromSourceGamma()...) | |
checkLen() | |
return items, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment