December 2017
Intermediate to advanced
316 pages
6h 58m
English
Sometimes, as part of the API, we should serve static files. The other application of httprouter is building scalable file servers. It means that we can build a Content Delivery Platform of our own. Some of the clients need static files from the server. Traditionally, we use Apache2 or Nginx for that purpose. But, from within the Go server, in order to serve the static files, we need to route them through a universal route like this:
/static/*
See the following code snippet for our implementation. The idea is to use the http.Dir method to load the filesystem, and then use the ServeFiles function of the httprouter instance. It should serve all the files in the given public directory. Usually, ...
Read now
Unlock full access