Develop a Web Application in Go-lang

Seralahthan
3 min readJul 29, 2018

Go is a wonderful language for writing web services, because of its lightweight threads, modularity, and excellent integration with other services.

GO-Routines

Large web servers must run thousands of concurrent tasks.One of the defining features of the Go programming language is that concurrency is built in to the programming language.

Go-routines, lightweight threads, enable the developer to perform multiple functions at the same time, quite like an assembly line. These are so helpful for web servers — for example, when anyone connects to my server, I just spawn a new go-routine to handle that client. It’s incredibly easy to do so as well.

Multi-threading is supported by many other languages, but Go’s implementation of go-routines makes managing these threads incredibly easy.

Modularity

Large web services with a large base of code should be maintained and improved in discrete, organized pieces. One of Go’s features that I most enjoy is how easy it is to develop a large application by modularizing your code.

Although you are writing many lines of Go code for this application, it doesn’t feel like a big heap of code which is tied together. It instead feels almost like a symphony, with each function performing its part.

Debugging in go is very efficient, because the modularity helps you know where to locate and solve your problem. This is because all the relevant function, constant, variable, and type declarations are kept in predictable places. Although some developers coming from more traditional programming languages argue how this could limit your freedom of code style, but in my opinion it’s much better to just follow what works.

The best part is, much of this organization is automatically handled by the `go fmt` tool. By calling this tool on your code, you automatically format your code to the agreed Go specifications — I personally use the Go- Sublime package of Sublime Text so this is done every time I save the file . The other organization comes from following the Go best practice on documenting your code.

Also, I have to mention Go’s package build system. Rather than searching each imported library and importing the dependencies for each library, it builds each imported package into a single executable that can be directly imported. To illustrate my point, if you’re using packages A and B which both call a package C, package C only needs to be built once (instead of having the code being imported and built into each package separately). This allows for incredibly speedy build times. Another huge plus for using Go.

Integration with third party software/built-ins

Web services need to perform a variety of functions. You don’t want to write all of that code yourself.

Luckily, Go interfaces quite nicely with common tools either through builtin or third party libraries. Here are the most notable examples of services a web-service can integrate with:

Builtins

  • Cryptography libraries (RSA, AES, crypto-safe random number generation)
  • Secure web protocols (TLS and SSL)
  • HTTP server (with HTML templates)

Third party

  • MongoDB
  • Amazon S3

Fortunately, all of these functionalities are enabled by free online libraries which are thoroughly documented. Although I can understand how some developers would be concerned about a lack of libraries in Go because it is still a relatively young programming language (released in 2009), I personally have not found this to be a problem at all.

Since the final product of a Go application is a binary executable, it can be integrated in a wide variety of applications and environments.

--

--

Seralahthan
Seralahthan

Written by Seralahthan

Consultant - Integration & CIAM | ATL@WSO2 | BScEng(Hons) in Computer Engineering | Interested in BigData, ML & AI

No responses yet