We could use QuoteIdentifier
db.Exec(fmt.Sprintf("CREATE TABLE %s", pq.QuoteIdentifier(table)))
Here are the lines from the documentation -
QuoteIdentifier quotes an "identifier" (e.g. a table or a column name) to be
used as part of an SQL statement.
For example:
tblname := "my_table"
data := "my_data"
quoted := pq.QuoteIdentifier(tblname)
err := db.Exec(fmt.Sprintf("INSERT INTO %s VALUES ($1)", quoted), data)
Any double quotes in name will be escaped.
The quoted identifier will be case sensitive when used in a query.
If the input string contains a zero byte, the result will be truncated immediately before it.