Add documentation for NotifyUploadProgress

This commit is contained in:
Marius 2017-02-21 23:17:07 +01:00
parent 68b6b20688
commit 73b273d4bd
2 changed files with 16 additions and 2 deletions

View File

@ -31,6 +31,8 @@ type Config struct {
// NotifyTerminatedUploads indicates whether sending notifications about
// terminated uploads using the TerminatedUploads channel should be enabled.
NotifyTerminatedUploads bool
// NotifyUploadProgress indicates whether sending notifications about
// the upload progress using the UploadProgress channel should be enabled.
NotifyUploadProgress bool
// Logger is the logger to use internally, mostly for printing requests.
Logger *log.Logger

View File

@ -85,6 +85,14 @@ type UnroutedHandler struct {
// happen if the NotifyTerminatedUploads field is set to true in the Config
// structure.
TerminatedUploads chan FileInfo
// UploadProgress is used to send notifications about the progress of the
// currently running uploads. For each open PATCH request, every second
// a FileInfo instance will be send over this channel with the Offset field
// being set to the number of bytes which have been transfered to the server.
// Please be aware that this number may be higher than the number of bytes
// which have been stored by the data store! Sending to this channel will only
// happen if the NotifyUploadProgress field is set to true in the Config
// structure.
UploadProgress chan FileInfo
// Metrics provides numbers of the usage for this handler.
Metrics Metrics
@ -663,6 +671,10 @@ func (w *progressWriter) Write(b []byte) (int, error) {
return len(b), nil
}
// sendProgressMessage will send a notification over the UploadProgress channel
// every second, indicating how much data has been transfered to the server.
// It will stop sending these instances once the returned channel has been
// closed. The returned reader should be used to read the request body.
func (handler *UnroutedHandler) sendProgressMessages(info FileInfo, reader io.Reader) (io.Reader, chan<- struct{}) {
progress := &progressWriter{
Offset: info.Offset,