Very new to Golang and unable to resolve this. Any help would be highly appreciated.
This is the code I need help with. Trying to pass the latitude etc into the query below, but unable to do it. Looking for the equivalent on ${latitude} in node js...
latitude := r.URL.Query().Get("lat")
longitude := r.URL.Query().Get("lon")
radius := r.URL.Query().Get("rad")
row := db.QueryRow(`SELECT "name", "website", "coordinates",
"description", "rating"
FROM geospots
WHERE ST_DWithin("coordinates", ST_MakePoint(latitude = $1,
longitude = $2)::geography, radius = $3)`, latitude, longitude)
Error:
andlers/SpotsInArea.go:15:5: latitude declared but not used
handlers/SpotsInArea.go:16:5: longitude declared but not used
handlers/SpotsInArea.go:17:5: radius declared but not used
QueryRowmethod just after the SQL string. And also you need to put parameter placeholders into the SQL string. For postgres it's$1,$2, and so on.$1once and$2twice and then passes two arguments"orange"and64. The$1in the SQL will be replaced with"orange"and the two$2will both be replaced with64.SELECT "name", "website", "coordinates", "description", "rating" FROM geospots WHERE ST_DWithin("coordinates", ST_MakePoint(latitude = $1, longitude = $2)::geography, radius = $3), latitude, longitude)$1instead oflatitude = $1. Same for the other three parameters. And you MUST pass all three arguments not just lat and long, i.e. where is radius? And the error means that lat long and radius are declared in a scope where they are not used. That means that the QueryRow that you have show is executed in some other function which has no access to those three variables. In Gov := xdoes not declare global variables if that's what you were hoping for.