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 Format1 min read
Helpdex
[email protected]
Linux Format4 min read
World of Goo 2
It’s been 16 long years since World of Goo squidged its way into our hearts and hard drives. The much-loved physics-based puzzle game was one of modern indie gaming’s earliest and biggest successes. But a lot has changed since then. Polished games fr
Linux Format3 min read
Kernel Watch
Linus Torvalds released the first Release Candidate (RC) kernel for what will become Linux 6.12 in the next couple of months. Among the new features in this kernel is a faster implementation of the getrandom system call using the kernel vDSO (virtual

Related Books & Audiobooks