I think you already know that the fish is not well. I suspect something wrong with the swim bladder like an infection, but it could be so many things. The obvious answer is to
take it to a pet/fish shop in a glass jar or plastic bag and let them have a look. Put the jar/bag in a dark bag to minimise stress.
Yes, goldfish can easily become bored and will swim against the glass up and down and sideways. This is why a bowl is totally unsuitable for a fish. The ideal setup will have a normal shaped tank with plenty of plastic plants and hiding places. Natural light coming in from the top and the back and sides of tank covered to give the fish max privacy.