If you notice your goldfish isn't doing so well, the first thing you should do is move it to a smaller tank if you have other fish. Fill a small bowl with new filtered water and move your fish to this "hospital" tank. Keep an eye on your fish for a few hours to see how it does. Sometimes changing the water can be enough to make them feel better. If your fish still isn't better after a few hours, unfortunately it may have a serious problem and will likely pass away. But if you were able to quarantine it quickly, hopefully any parasites or illness affecting it won't spread to your other fish.