Goldfish are cyprinids, in the same family as carp. Like other members of this family, they can take in oxygen at the waters surface. This is the surface "gulping" you see them doing. When you see this, tt also means that the water has a low oxygen content.
Many people DO put them in stocktanks and they seem to do alright. Two things likely accoutn for this:
There is a large surface area and there is a regular exchange of water. I would be concerned with the small surface area of a rain barrel as much as anything and think some aeration would be beneficial.
Also, "stuff" comes into a rain a barrel with the water run in - unless you filter the water, who knows what is getting in or what it will do to the fish?
Finally, cyprinids cannot digest proteins well and they quickly foul their water. Ensure you can exchange their water frequently to avoid toxin buildup.
A better sort of fish for a rain barrel was mentioned, the Betta, or Siamese Fighting Fish. But there is one that is superior to that - the Gourami. Like the Betta, Gourami's are labarynthine fish, having a hollow skull where oxygen, gulped from the surface, is stored. They can live in stagnant water quite well, without any aeration and will readily gobble mossie larvae. They will readily breed, too, but are bubble nesters, meaning they need calm water for nesting.
Their only downside is they will not overwinter, and must be removed prior to the cold season.
Goldfish or Goruami, I think you may be on to somehitng.