在Go中构造动态SQL查询

I am not very experienced developer in backend, and I am trying to build the simple CMS. I use go and gin framework, and database/sql package to interact with DB. So, the question is that sometimes I have to perform very similar queries, but they are slightly different. For example, sometimes I want to add where clause dynamically, or simply omit it. Or I have to create new row or updating existing – despite different query, they basically perform similar operations. Or I want to add or clause.

So, I write a lot of duplicated code. What is the best way to avoid it?