Codebase list golang-github-vbauerster-mpb / 26e2893
Refactoring: completeMsg from Struct{string} to *string Vladimir Bauer 7 years ago
7 changed file(s) with 49 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
177177
178178 type countersDecorator struct {
179179 WC
180 unit int
181 pairFormat string
182 complete *completeMsg
180 unit int
181 pairFormat string
182 completeMsg *string
183183 }
184184
185185 func (d *countersDecorator) Decor(st *Statistics) string {
186 if st.Completed && d.complete != nil {
187 return d.FormatMsg(d.complete.msg)
186 if st.Completed && d.completeMsg != nil {
187 return d.FormatMsg(*d.completeMsg)
188188 }
189189
190190 var str string
201201 }
202202
203203 func (d *countersDecorator) OnCompleteMessage(msg string) {
204 d.complete = &completeMsg{msg}
205 }
204 d.completeMsg = &msg
205 }
141141 }
142142 return decorator
143143 }
144
145 // completeMsg for internal usage.
146 type completeMsg struct {
147 msg string
148 }
2525
2626 type elapsedDecorator struct {
2727 WC
28 style int
29 startTime time.Time
30 complete *completeMsg
28 style int
29 startTime time.Time
30 completeMsg *string
3131 }
3232
3333 func (d *elapsedDecorator) Decor(st *Statistics) string {
34 if st.Completed && d.complete != nil {
35 return d.FormatMsg(d.complete.msg)
34 if st.Completed && d.completeMsg != nil {
35 return d.FormatMsg(*d.completeMsg)
3636 }
3737
3838 var str string
5656 }
5757
5858 func (d *elapsedDecorator) OnCompleteMessage(msg string) {
59 d.complete = &completeMsg{msg}
59 d.completeMsg = &msg
6060 }
4242
4343 type movingAverageETA struct {
4444 WC
45 style int
46 average ewma.MovingAverage
47 complete *completeMsg
45 style int
46 average ewma.MovingAverage
47 completeMsg *string
4848 }
4949
5050 func (d *movingAverageETA) Decor(st *Statistics) string {
51 if st.Completed && d.complete != nil {
52 return d.FormatMsg(d.complete.msg)
51 if st.Completed && d.completeMsg != nil {
52 return d.FormatMsg(*d.completeMsg)
5353 }
5454
5555 v := internal.Round(d.average.Value())
8686 }
8787
8888 func (d *movingAverageETA) OnCompleteMessage(msg string) {
89 d.complete = &completeMsg{msg}
89 d.completeMsg = &msg
9090 }
9191
9292 // AverageETA decorator.
110110
111111 type averageETA struct {
112112 WC
113 style int
114 startTime time.Time
115 complete *completeMsg
113 style int
114 startTime time.Time
115 completeMsg *string
116116 }
117117
118118 func (d *averageETA) Decor(st *Statistics) string {
119 if st.Completed && d.complete != nil {
120 return d.FormatMsg(d.complete.msg)
119 if st.Completed && d.completeMsg != nil {
120 return d.FormatMsg(*d.completeMsg)
121121 }
122122
123123 var str string
146146 }
147147
148148 func (d *averageETA) OnCompleteMessage(msg string) {
149 d.complete = &completeMsg{msg}
149 d.completeMsg = &msg
150150 }
2929 type nameDecorator struct {
3030 WC
3131 msg string
32 complete *completeMsg
32 complete *string
3333 }
3434
3535 func (d *nameDecorator) Decor(st *Statistics) string {
3636 if st.Completed && d.complete != nil {
37 return d.FormatMsg(d.complete.msg)
37 return d.FormatMsg(*d.complete)
3838 }
3939 return d.FormatMsg(d.msg)
4040 }
4141
4242 func (d *nameDecorator) OnCompleteMessage(msg string) {
43 d.complete = &completeMsg{msg}
43 d.complete = &msg
4444 }
2222
2323 type percentageDecorator struct {
2424 WC
25 complete *completeMsg
25 completeMsg *string
2626 }
2727
2828 func (d *percentageDecorator) Decor(st *Statistics) string {
29 if st.Completed && d.complete != nil {
30 return d.FormatMsg(d.complete.msg)
29 if st.Completed && d.completeMsg != nil {
30 return d.FormatMsg(*d.completeMsg)
3131 }
3232 str := fmt.Sprintf("%d %%", internal.Percentage(st.Total, st.Current, 100))
3333 return d.FormatMsg(str)
3434 }
3535
3636 func (d *percentageDecorator) OnCompleteMessage(msg string) {
37 d.complete = &completeMsg{msg}
37 d.completeMsg = &msg
3838 }
161161
162162 type movingAverageSpeed struct {
163163 WC
164 unit int
165 unitFormat string
166 average ewma.MovingAverage
167 msg string
168 complete *completeMsg
164 unit int
165 unitFormat string
166 average ewma.MovingAverage
167 msg string
168 completeMsg *string
169169 }
170170
171171 func (d *movingAverageSpeed) Decor(st *Statistics) string {
172172 if st.Completed {
173 if d.complete != nil {
174 return d.FormatMsg(d.complete.msg)
173 if d.completeMsg != nil {
174 return d.FormatMsg(*d.completeMsg)
175175 }
176176 return d.FormatMsg(d.msg)
177177 }
199199 }
200200
201201 func (d *movingAverageSpeed) OnCompleteMessage(msg string) {
202 d.complete = &completeMsg{msg}
202 d.completeMsg = &msg
203203 }
204204
205205 // AverageSpeed decorator with dynamic unit measure adjustment.
230230
231231 type averageSpeed struct {
232232 WC
233 unit int
234 unitFormat string
235 startTime time.Time
236 msg string
237 complete *completeMsg
233 unit int
234 unitFormat string
235 startTime time.Time
236 msg string
237 completeMsg *string
238238 }
239239
240240 func (d *averageSpeed) Decor(st *Statistics) string {
241241 if st.Completed {
242 if d.complete != nil {
243 return d.FormatMsg(d.complete.msg)
242 if d.completeMsg != nil {
243 return d.FormatMsg(*d.completeMsg)
244244 }
245245 return d.FormatMsg(d.msg)
246246 }
261261 }
262262
263263 func (d *averageSpeed) OnCompleteMessage(msg string) {
264 d.complete = &completeMsg{msg}
265 }
264 d.completeMsg = &msg
265 }