Of course, our little project can't really be complete without a proper frontend for our users! To build one, we will leverage the Go standard library's support for HTML templates (the text/template and html/template packages) to design a fully functioning static website for Links 'R' Us. For simplicity, all the HTML templates will be embedded into our application as strings and parsed into text.Template when the application starts. In terms of functionality, our frontend must implement a number of features.
First, it must implement an index/landing page where the user can enter a search query. Queries can either be keyword- or phrase-based. The index page should also include a link that can navigate users to another page where they can submit a website for indexing. The following screenshot shows a rendering of the index page template:
Next, we need a page where webmasters can manually submit their websites for indexing. As we mentioned previously, the index/landing page will include a link to the site submission page. The following screenshot shows what the rendered site submission page for indexing will look like:
The final, and obviously most important, page in our entire application is the search results page. As shown in the following screenshot, the results page renders a paginated list of websites matching the user's search query. The header of the page includes a search text box that displays the currently searched term and allows users to change their search terms without leaving the page:
The template for rendering the individual search result blocks, as portrayed in the preceding screenshot, consists of three sections:
- A link to the web page. The link text will either display the title of the matched page or the link to the page itself, depending on whether the crawler was able to extract its title.
- The URL to the matched web page in a smaller font.
- A summary of the page's contents where the matched keywords are highlighted.
Now that we have defined all the necessary templates for rendering the pages that compose the Links 'R' Us frontend, we need to register a series of HTTP routes to allow our end users to access our service.