refactoring: newProxyReader
Vladimir Bauer
3 years ago
| 53 | 53 | return n, err |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | func (b *Bar) newProxyReader(r io.Reader, hasEwma bool) (rc io.ReadCloser) { | |
| 56 | func (b *Bar) newProxyReader(r io.Reader, hasEwma bool) io.ReadCloser { | |
| 57 | 57 | pr := proxyReader{toReadCloser(r), b} |
| 58 | if hasEwma { | |
| 59 | epr := ewmaProxyReader{pr} | |
| 60 | if wt, ok := r.(io.WriterTo); ok { | |
| 61 | pwt := proxyWriterTo{pr, wt} | |
| 62 | return ewmaProxyWriterTo{epr, pwt} | |
| 63 | } | |
| 64 | return epr | |
| 65 | } | |
| 58 | 66 | if wt, ok := r.(io.WriterTo); ok { |
| 59 | pw := proxyWriterTo{pr, wt} | |
| 60 | if hasEwma { | |
| 61 | rc = ewmaProxyWriterTo{ewmaProxyReader{pr}, pw} | |
| 62 | } else { | |
| 63 | rc = pw | |
| 64 | } | |
| 65 | } else if hasEwma { | |
| 66 | rc = ewmaProxyReader{pr} | |
| 67 | } else { | |
| 68 | rc = pr | |
| 67 | return proxyWriterTo{pr, wt} | |
| 69 | 68 | } |
| 70 | return rc | |
| 69 | return pr | |
| 71 | 70 | } |
| 72 | 71 | |
| 73 | 72 | func toReadCloser(r io.Reader) io.ReadCloser { |