GopherJS fundamentals

GopherJS is a set of tools, data types, and Go packages that allows you to compile Go code to JavaScript. Compiling the code of one programming language to another is also known as transpiling. GopherJS is very useful for Go developers who are not very proficient in JavaScript, because it allows you to write code in Go that can be integrated with JavaScript modules. This means that you can write code in Go that empowers the frontend of your application, or can be integrated with Node.js modules, offering you the flexibility of JavaScript combined with the power of Go.

GopherJS is a very a powerful piece of software that is used in numerous applications. However, in order to effectively utilize GopherJS, you need to understand its building blocks. The first step is to retrieve the package using the go get command:

go get -u github.com/gopherjs/gopherjs

Also, to be able to run some of GopherJS commands, we need to install the source-map-support node module:

npm install --global source-map-support

This allows you to debug your code from Go when the need arises. This is very useful when writing non-trivial applications in GopherJS.

Great, now we are ready to explore the package a bit more. GopherJS provides a playground where you can test your GopherJS code at https://gopherjs.github.io/playground/.

Now that our GopherJS is set up, let's take a look at the GopherJS types.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.214.155