Question about Go syntax returning an empty struct upon error
func FindBeerByID(ID int) (Beer, error) {
	for i := 0; i < len(beers); i++ {
		if beers[i].ID == ID {
			return beers[i], nil
		}
	}
	return Beer{}, errors.New(fmt.Sprintf("Could not find beer with id %v", ID))
}

I come from JS so I appreciate the tips!

Should I be returning Beer() here? It feels odd to me and I would expect to return something like nil.

Comments (1)