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.
Start your free 30 days