writeCacheReader: rename all vars to use full redable words

This commit is contained in:
6543 2022-11-12 00:38:21 +01:00
parent cf78f5fda2
commit da84be2352
No known key found for this signature in database
GPG key ID: B8BE6D610E61C862

View file

@ -71,32 +71,33 @@ type BranchTimestamp struct {
} }
type writeCacheReader struct { type writeCacheReader struct {
rc io.ReadCloser originalReader io.ReadCloser
buff *bytes.Buffer buffer *bytes.Buffer
f *FileResponse rileResponse *FileResponse
cacheKey string cacheKey string
cache cache.SetGetKey cache cache.SetGetKey
hasErr bool hasError bool
} }
func (t *writeCacheReader) Read(p []byte) (n int, err error) { func (t *writeCacheReader) Read(p []byte) (n int, err error) {
n, err = t.rc.Read(p) n, err = t.originalReader.Read(p)
if err != nil { if err != nil {
t.hasErr = true log.Trace().Err(err).Msgf("[cache] original reader for %q has returned an error", t.cacheKey)
t.hasError = true
} else if n > 0 { } else if n > 0 {
_, _ = t.buff.Write(p[:n]) _, _ = t.buffer.Write(p[:n])
} }
return return
} }
func (t *writeCacheReader) Close() error { func (t *writeCacheReader) Close() error {
if !t.hasErr { if !t.hasError {
fc := *t.f fc := *t.rileResponse
fc.Body = t.buff.Bytes() fc.Body = t.buffer.Bytes()
_ = t.cache.Set(t.cacheKey, fc, fileCacheTimeout) _ = t.cache.Set(t.cacheKey, fc, fileCacheTimeout)
} }
log.Trace().Msgf("cacheReader for %q saved=%t closed", t.cacheKey, !t.hasErr) log.Trace().Msgf("cacheReader for %q saved=%t closed", t.cacheKey, !t.hasError)
return t.rc.Close() return t.originalReader.Close()
} }
func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey, cacheKey string) io.ReadCloser { func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey, cacheKey string) io.ReadCloser {
@ -106,9 +107,9 @@ func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey,
} }
return &writeCacheReader{ return &writeCacheReader{
rc: r, originalReader: r,
buff: bytes.NewBuffer(make([]byte, 0)), buffer: bytes.NewBuffer(make([]byte, 0)),
f: &f, rileResponse: &f,
cache: cache, cache: cache,
cacheKey: cacheKey, cacheKey: cacheKey,
} }