Wales’ Geraint Thomas survived a late puncture to win gold in a rain-soaked Commonwealth Games men’s road race in Glasgow.