Skip to content
This repository has been archived by the owner on May 10, 2020. It is now read-only.

Files

Latest commit

Jan 1, 2018
593aae8 · Jan 1, 2018

History

History
24 lines (19 loc) · 596 Bytes

README.md

File metadata and controls

24 lines (19 loc) · 596 Bytes

cache-control

cache-control middleware adds ETag header (md5 of the content) and Cache-Control header

sample usage

Using chi router, we register this middleware before a http.FileServer:

fs := http.Dir(`./assets`)
assetServer := http.FileServer(fs)
rt.Route("/assets/*", func(rt chi.Router) {
	rt.Use(cachecontrol.CacheControl(
		fs,
		cachecontrol.StripPrefix("/assets")))
	rt.Get(
		"/*",
		http.StripPrefix("/assets", assetServer).ServeHTTP)
})

TODO

  • dirwatch can be used for watching directories of assets (next).
  • more tests