This is deployed right now. Head over to https://shakesearch.micahparks.com or use the command line:
curl "https://shakesearch.micahparks.com/api/search?q=Porter&maxResults=2" | python3 -m json.tool
Output:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 165 100 165 0 0 283 0 --:--:-- --:--:-- --:--:-- 282
[
{
"line": "PORTER.",
"lineNumbers": [
81739,
81764,
81771,
81783
],
"matchedIndexes": [
0,
1,
2,
3,
4,
5
]
},
{
"line": "A PORTER",
"lineNumbers": [
50287
],
"matchedIndexes": [
2,
3,
4,
5,
6,
7
]
}
]
I kept most of the lovely frontend the same, but I fixed up the backend and added new features as instructed.
You can click on the hyperlink of the line number to jump to a snippet from Shakespeare's complete works. From there you can scroll up and down for a few hundred lines, but it's only a snippet. Transferring the entire document would take too long.
- Swagger 2.0 specification file. This helps communicate API and data structures to other developers.
- See it live here: https://shakesearch.micahparks.com/docs.'
- Line numbers link to snippets of the complete works.
- This uses Go templating.
- Fuzzy search the given query using
fuzzy
. - Rate limit requests with
tollbooth
. - Using a logger (
zap
). - Deployment assets:
Dockerfile
,docker-compose.yml
, andCaddyfile
. - Proper error handing.
- Configurable hostname, port, and file location for Shakespeare's works in the file system.
- Limit the number of results using query.
- More data returned from search endpoint.
- Endpoints moved to
/api
. Ex:/api/search
. - Separation of frontend and backend code. (Using Caddy as a file server).
- HTTPS (thanks to Let's Encrypt and Caddy).
- No more panics when a query causes an impossible index. Ex. Search for something near the top or bottom of the file
like
Project
. - Bold the text that matched the query.
- Line number where the text came from.
- Less whitespace in memory.
Environment variable table:
Name | Description | Default Value | Example Value |
---|---|---|---|
HOST |
The host to bind the service to. | localhost |
0.0.0.0 |
PORT |
The port to bind the service to. | random | 30000 |
SHAKESPEARES_WORKS |
The full or relative file path to a text file containing the complete works of Shakespeare. | completeworks.txt |
/home/william/works.txt |
SNIPPET_TEMPLATE |
The full or relative file path to the HTML template for a snippet of Shakespeare's works. | snippet.gohtml |
customTempalte.gohtml |
This project uses a swagger 2.0 API (swagger.yml
) and
the goswagger project. The swagger.yml
file was used to generate the code
in the cmd
, models
, and restapi
directories. One file was edited at restapi/configure_shakesearch.go
.
The other directories are not from the code generator. Both configure
and endpoints
contain hand written code and
the static
directory was given, except static/app.js
was modified a bit to help show matching results with bold
text.