Created
August 30, 2018 15:30
-
-
Save pdk/7ddbf4878b3828a96512e01e77b94e64 to your computer and use it in GitHub Desktop.
example of non-error checking in go 1
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) { | |
var items []string | |
items = append(items, GetItemsFromSourceAlpha()...) | |
if len(items) > n { | |
return items, fmt.Errorf("more than %d items gathered: %d", n, len(items)) | |
} | |
items = append(items, GetItemsFromSourceBeta()...) | |
if len(items) > n { | |
return items, fmt.Errorf("more than %d items gathered: %d", n, len(items)) | |
} | |
items = append(items, GetItemsFromSourceGamma()...) | |
if len(items) > n { | |
return items, fmt.Errorf("more than %d items gathered: %d", n, len(items)) | |
} | |
return items, nil | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment