Communication between Go and Javascript is a challenge IMHO.
My experience is that when you query a database the result must be included in a html template and rendered at the server. SSR (server side rendering). I have found no other way to communicate with the webpage (other than Websockets - maybe)
Both SSR (Server Side Rendering) and CSR (Client Side Rendering) have their benefits. But a mix of them is SSG (Static Site Generation) may be more beneficial. Which means that Go renders the HTML at build time from templates and all dynamic content provided by AJAX (Javascript). I connect an API created by Go (with SQL queries) and AJAX to call this API. I think you get the best of the two worlds. Go is good as an API and AJAX is good for REST queries.
SSG with AJAX reduce the page flickering as it only renders a part of the page. So my conclusion is to use AJAX to communicate with the API.
These are my conclusions. Hope to get proven wrong
var url = "https://api2.go4webdev.org/test/1";
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.setRequestHeader("Accept", "application/json");
xhr.onload = function () {
if (xhr.readyState === 4) {
document.getElementById("put").innerHTML = this.responseText
}};
xhr.send();