Welcome and thanks for your question!
There could be significant tax consequences of this transaction. How old are you?
If you are currently working, you can only take an in-service withdraw if you demonstrate financial need or are at least age 59 1/2.
Withdrawing to invest in gold would not qualify as financial need, so if you are still actively employed with the government, you would not be able to take a withdraw.
If you are not still employed, then you could withdraw your money, but I wouldn't advise it.
Any funds you withdraw, with the exception of Roth contributions, qualified Roth earnings or tax-exempt contributions, will be subject to tax at ordinary income tax rates. Depending on the amount you withdraw, this could be a very significant amount of tax, especially if you are under age 59 1/2. If you are under 59 1/2, you will have to pay an extra 10% penalty tax for early withdraw of retirement funds.