Refactoring: completeMsg from Struct{string} to *string
Vladimir Bauer
7 years ago
| 177 | 177 |
|
| 178 | 178 |
type countersDecorator struct {
|
| 179 | 179 |
WC
|
| 180 | |
unit int
|
| 181 | |
pairFormat string
|
| 182 | |
complete *completeMsg
|
|
180 |
unit int
|
|
181 |
pairFormat string
|
|
182 |
completeMsg *string
|
| 183 | 183 |
}
|
| 184 | 184 |
|
| 185 | 185 |
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)
|
| 188 | 188 |
}
|
| 189 | 189 |
|
| 190 | 190 |
var str string
|
|
| 201 | 201 |
}
|
| 202 | 202 |
|
| 203 | 203 |
func (d *countersDecorator) OnCompleteMessage(msg string) {
|
| 204 | |
d.complete = &completeMsg{msg}
|
| 205 | |
}
|
|
204 |
d.completeMsg = &msg
|
|
205 |
}
|
| 25 | 25 |
|
| 26 | 26 |
type elapsedDecorator struct {
|
| 27 | 27 |
WC
|
| 28 | |
style int
|
| 29 | |
startTime time.Time
|
| 30 | |
complete *completeMsg
|
|
28 |
style int
|
|
29 |
startTime time.Time
|
|
30 |
completeMsg *string
|
| 31 | 31 |
}
|
| 32 | 32 |
|
| 33 | 33 |
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)
|
| 36 | 36 |
}
|
| 37 | 37 |
|
| 38 | 38 |
var str string
|
|
| 56 | 56 |
}
|
| 57 | 57 |
|
| 58 | 58 |
func (d *elapsedDecorator) OnCompleteMessage(msg string) {
|
| 59 | |
d.complete = &completeMsg{msg}
|
|
59 |
d.completeMsg = &msg
|
| 60 | 60 |
}
|
| 42 | 42 |
|
| 43 | 43 |
type movingAverageETA struct {
|
| 44 | 44 |
WC
|
| 45 | |
style int
|
| 46 | |
average ewma.MovingAverage
|
| 47 | |
complete *completeMsg
|
|
45 |
style int
|
|
46 |
average ewma.MovingAverage
|
|
47 |
completeMsg *string
|
| 48 | 48 |
}
|
| 49 | 49 |
|
| 50 | 50 |
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)
|
| 53 | 53 |
}
|
| 54 | 54 |
|
| 55 | 55 |
v := internal.Round(d.average.Value())
|
|
| 86 | 86 |
}
|
| 87 | 87 |
|
| 88 | 88 |
func (d *movingAverageETA) OnCompleteMessage(msg string) {
|
| 89 | |
d.complete = &completeMsg{msg}
|
|
89 |
d.completeMsg = &msg
|
| 90 | 90 |
}
|
| 91 | 91 |
|
| 92 | 92 |
// AverageETA decorator.
|
|
| 110 | 110 |
|
| 111 | 111 |
type averageETA struct {
|
| 112 | 112 |
WC
|
| 113 | |
style int
|
| 114 | |
startTime time.Time
|
| 115 | |
complete *completeMsg
|
|
113 |
style int
|
|
114 |
startTime time.Time
|
|
115 |
completeMsg *string
|
| 116 | 116 |
}
|
| 117 | 117 |
|
| 118 | 118 |
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)
|
| 121 | 121 |
}
|
| 122 | 122 |
|
| 123 | 123 |
var str string
|
|
| 146 | 146 |
}
|
| 147 | 147 |
|
| 148 | 148 |
func (d *averageETA) OnCompleteMessage(msg string) {
|
| 149 | |
d.complete = &completeMsg{msg}
|
|
149 |
d.completeMsg = &msg
|
| 150 | 150 |
}
|
| 29 | 29 |
type nameDecorator struct {
|
| 30 | 30 |
WC
|
| 31 | 31 |
msg string
|
| 32 | |
complete *completeMsg
|
|
32 |
complete *string
|
| 33 | 33 |
}
|
| 34 | 34 |
|
| 35 | 35 |
func (d *nameDecorator) Decor(st *Statistics) string {
|
| 36 | 36 |
if st.Completed && d.complete != nil {
|
| 37 | |
return d.FormatMsg(d.complete.msg)
|
|
37 |
return d.FormatMsg(*d.complete)
|
| 38 | 38 |
}
|
| 39 | 39 |
return d.FormatMsg(d.msg)
|
| 40 | 40 |
}
|
| 41 | 41 |
|
| 42 | 42 |
func (d *nameDecorator) OnCompleteMessage(msg string) {
|
| 43 | |
d.complete = &completeMsg{msg}
|
|
43 |
d.complete = &msg
|
| 44 | 44 |
}
|
| 22 | 22 |
|
| 23 | 23 |
type percentageDecorator struct {
|
| 24 | 24 |
WC
|
| 25 | |
complete *completeMsg
|
|
25 |
completeMsg *string
|
| 26 | 26 |
}
|
| 27 | 27 |
|
| 28 | 28 |
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)
|
| 31 | 31 |
}
|
| 32 | 32 |
str := fmt.Sprintf("%d %%", internal.Percentage(st.Total, st.Current, 100))
|
| 33 | 33 |
return d.FormatMsg(str)
|
| 34 | 34 |
}
|
| 35 | 35 |
|
| 36 | 36 |
func (d *percentageDecorator) OnCompleteMessage(msg string) {
|
| 37 | |
d.complete = &completeMsg{msg}
|
|
37 |
d.completeMsg = &msg
|
| 38 | 38 |
}
|
| 161 | 161 |
|
| 162 | 162 |
type movingAverageSpeed struct {
|
| 163 | 163 |
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
|
| 169 | 169 |
}
|
| 170 | 170 |
|
| 171 | 171 |
func (d *movingAverageSpeed) Decor(st *Statistics) string {
|
| 172 | 172 |
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)
|
| 175 | 175 |
}
|
| 176 | 176 |
return d.FormatMsg(d.msg)
|
| 177 | 177 |
}
|
|
| 199 | 199 |
}
|
| 200 | 200 |
|
| 201 | 201 |
func (d *movingAverageSpeed) OnCompleteMessage(msg string) {
|
| 202 | |
d.complete = &completeMsg{msg}
|
|
202 |
d.completeMsg = &msg
|
| 203 | 203 |
}
|
| 204 | 204 |
|
| 205 | 205 |
// AverageSpeed decorator with dynamic unit measure adjustment.
|
|
| 230 | 230 |
|
| 231 | 231 |
type averageSpeed struct {
|
| 232 | 232 |
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
|
| 238 | 238 |
}
|
| 239 | 239 |
|
| 240 | 240 |
func (d *averageSpeed) Decor(st *Statistics) string {
|
| 241 | 241 |
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)
|
| 244 | 244 |
}
|
| 245 | 245 |
return d.FormatMsg(d.msg)
|
| 246 | 246 |
}
|
|
| 261 | 261 |
}
|
| 262 | 262 |
|
| 263 | 263 |
func (d *averageSpeed) OnCompleteMessage(msg string) {
|
| 264 | |
d.complete = &completeMsg{msg}
|
| 265 | |
}
|
|
264 |
d.completeMsg = &msg
|
|
265 |
}
|