The term gaoli (高麗, Goryeo) is used to express one of the ancient Korean kingdoms. The term bangzi (棒子) is used to express billy club.
One of the popular yet incorrect beliefs is that the term is originated from the baton-wielding Korean guards during the Japanese occupation of Manchuria. Not trusted by the Japanese, the Korean guards were not given firearms, only batons. The guards often enjoyed teasing Chinese people and beating them with batons, earning enmity among the Chinese. But the use of this slang is seen as early as Emperor Kangxi's time, so the above explanation doesn't work. At the moment no one knows the exact origin of Gaoli Bangzi.