progress.go 750 B

123456789101112131415161718192021
  1. package blob
  2. import "context"
  3. type contextKey string
  4. var progressCallbackContextKey contextKey = "progress-callback"
  5. // ProgressFunc is used to report progress of a long-running storage operation.
  6. type ProgressFunc func(desc string, completed, total int64)
  7. // WithUploadProgressCallback returns a context that passes callback function to be used storage upload progress.
  8. func WithUploadProgressCallback(ctx context.Context, callback ProgressFunc) context.Context {
  9. return context.WithValue(ctx, progressCallbackContextKey, callback)
  10. }
  11. // ProgressCallback gets the progress callback function from the context.
  12. func ProgressCallback(ctx context.Context) ProgressFunc {
  13. pf, _ := ctx.Value(progressCallbackContextKey).(ProgressFunc)
  14. return pf
  15. }