package progress import ( "fmt" "io" "sync" ) type Reporter struct { Total int cur int mu sync.Mutex writer io.Writer } func NewReporter(writer io.Writer) Reporter { return Reporter{writer: writer} } func (r *Reporter) ReportProgress(num int) { r.mu.Lock() if num > r.cur { fmt.Fprintf(r.writer, "%d/%d\n", num, r.Total) r.cur = num } r.mu.Unlock() }