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 {
rc io.ReadCloser
buff *bytes.Buffer
f *FileResponse
cacheKey string
cache cache.SetGetKey
hasErr bool
originalReader io.ReadCloser
buffer *bytes.Buffer
rileResponse *FileResponse
cacheKey string
cache cache.SetGetKey
hasError bool
}
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 {
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 {
_, _ = t.buff.Write(p[:n])
_, _ = t.buffer.Write(p[:n])
}
return
}
func (t *writeCacheReader) Close() error {
if !t.hasErr {
fc := *t.f
fc.Body = t.buff.Bytes()
if !t.hasError {
fc := *t.rileResponse
fc.Body = t.buffer.Bytes()
_ = t.cache.Set(t.cacheKey, fc, fileCacheTimeout)
}
log.Trace().Msgf("cacheReader for %q saved=%t closed", t.cacheKey, !t.hasErr)
return t.rc.Close()
log.Trace().Msgf("cacheReader for %q saved=%t closed", t.cacheKey, !t.hasError)
return t.originalReader.Close()
}
func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey, cacheKey string) io.ReadCloser {
@ -106,10 +107,10 @@ func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey,
}
return &writeCacheReader{
rc: r,
buff: bytes.NewBuffer(make([]byte, 0)),
f: &f,
cache: cache,
cacheKey: cacheKey,
originalReader: r,
buffer: bytes.NewBuffer(make([]byte, 0)),
rileResponse: &f,
cache: cache,
cacheKey: cacheKey,
}
}