To cache HTTP requests on the file system, you can use the ioutil package in Go. Here's an example implementation:
main.go1329 chars52 lines
In this example, we check if the cached response is available on the file system using os.Stat, if it is available we read the contents of the file using ioutil.ReadFile and return that as the response. If the cached response is not available, we fetch the response from the web server using http.Get, then read and return the response body. Finally, we write the response body to the cache using ioutil.WriteFile.
gistlibby LogSnag