Serving static files
In the previous chapters, you have seen how to render API responses in JSON and XML formats. In this chapter, you will learn how you can render different types of responses. We will start by serving a basic index.html file and then move on to serving static files, such as JavaScript, CSS files, and images from a filesystem, and eventually render HTML templates.
To start serving static files, follow these steps:
- Create a new project folder and open it with the VSCode IDE. Then, create an
index.htmlfile to display aHello worldmessage with an<h2>tag, as follows:<html> <head> Â Â Â <title>Recipes Platform</title> </head> <body> Â Â Â <h2>Hello world</h2> </body> </html>
- Next, with the
go getcommand, installgithub.com/gin-gonic/gin, write amain.gofile, and define a router with thegin.Default()method. Then, define a route for theindexpage and register...