Linux Format

Get the most from the Gin HTTP framework

Calm down vicar. The gin we’re talking about is an open source web framework (a collection of libraries and APIs) written in Go that can help you develop powerful HTTP services. All the code discussed here can be found in the https://github.com/mactsouk/LXF.285 GitHub repository. If you want to download all the code for this tutorial from GitHub then you’ll need to run the following three commands:

You need to run cd LXF.285 to go into that directory. We’re now ready to continue with the rest of the tutorial.

A basic server

One of the files found in the repository is called introGin. go and is located inside the /simple directory. introGin. go implements a simple HTTP server and is going to be used in this section to help you understand how to create projects with Gin. The important code in introGin. go is the following:

The first statement creates an Engine instance (with the Logger and Recovery middleware already attached) whereas the second one starts the HTTP server at the port number stored in the PORT string variable (:8008). If you don’t specify the address the server will listen to, it’ll listen to all available network interfaces.

Because this is an empty from within the simple directory requires executing the following commands:

You’re reading a preview, subscribe to read more.

More from Linux Format

Linux Format5 min read
Some Ansible Advice For Around The Home!
Of late, this writer has been busy creating new virtual hosts for different things and decided that it would be an ideal time to get stuck into Ansible. Things have evolved in system management since Bash. Ansible is a great way to deploy software c
Linux Format14 min read
Ubuntu at 20
Without Ubuntu, the current Linux landscape would be unrecognisable. Back in October 2004, the first 4.10 (2004.10) release of Ubuntu, with its intriguing Warty Warthog code name, leapt from obscurity to being one of the most downloaded Linux distrib
Linux Format3 min read
Kernel Watch
Linus Torvalds announced the fourth RC (Release Candidate) for what will become Linux 6.9 in another few weeks. In his announcement, he noted that there was “Nothing particularly unusual going on this week – some new hardware mitigations may stand o

Related Books & Audiobooks