February 2020
Intermediate to advanced
404 pages
8h 42m
English
Sometimes, an API can serve files. The other application of httprouter, apart from routing, is building an efficient file server. It means that we can build a content delivery platform of our own. Some clients need static files from the server. Traditionally, we use Apache2 or Nginx for that purpose. If one has to create something similar purely in Go, they can leverage httprouter.
Let us build one. From the Go server, in order to serve the static files, we need to route them through a universal route, like this:
/static/*
The plan is to use http package's Dir method to load the filesystem, and pass filesystem handler it returns to httprouter. We can use the ServeFiles function of the httprouter ...
Read now
Unlock full access