It is a metaphor: gold is a comparison evoking something precious, next to the heart which is itself a metaphor of generosity and empathy (“Have a heart!”) So, “heart of gold” is a double metaphor, but it has become an idiom through frequent use in the sense of “a generous disposition”.figure out