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

workshop-depot/cache-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published