I am writing some microservices in Go which handle different files.
I want to transfer files from one service, the client, to another, the server, via PUT method. The service works, but there is a small point which is not elegant. The files I transfer are getting a new modification date, when I write them on the file system of the server.
At the moment I handle the http.Request
at the server like this:
- ensure that there is a file at the server
- copy the body from the request to the server
io.Copy(myfile, r.Body)
When I do that the file has the last modification date from now(). To solve this problem I could transfer a timestamp of the original file and set it via io.Chtimes()
. But the request.Body implements an io.ReadCloser
interface, so I think there must be a more elegant way to implement the writing of the file onto the server. Is there a function, which takes an io.Reader
which preserves the timestamp of the file?
If not, is there a solution for REST services for this problem?