It is really cool to run Go code in the browser. GopherJS is a compiler from
Go to JavaScript, which makes this possible.
In this post, we will show how to use XMLHttpRequest (XHR) to send HTTP GET
requests to retrieve JSON data from remote server.
{"data":[["\u25ce\u3000\u300aConcise Pali-English Dictionary\u300b by A.P. Buddhadatta Mahathera","sukhada",": [adj.] producing happiness."]],"word":"sukhada"}
It is surprising easy to send HTTP GETXHR request: Use Golang built-in
net/http package! You just use Get method as usual, and GopherJS will take
care of all the rests for you!
Put demo.js together with the index.html and sukhada.json in the same
directory. You need a simple HTTP server to run this demo. Use
GopherJS serve command to serve the above files, and open your browser
console to see the output.