Skip to content

Instantly share code, notes, and snippets.

@pdk
Created August 30, 2018 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdk/7ddbf4878b3828a96512e01e77b94e64 to your computer and use it in GitHub Desktop.
Save pdk/7ddbf4878b3828a96512e01e77b94e64 to your computer and use it in GitHub Desktop.
example of non-error checking in go 1
// 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