mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-11-05 14:07:01 +00:00
writeCacheReader: rename all vars to use full redable words
This commit is contained in:
parent
cf78f5fda2
commit
da84be2352
1 changed files with 20 additions and 19 deletions
|
@ -71,32 +71,33 @@ type BranchTimestamp struct {
|
|||
}
|
||||
|
||||
type writeCacheReader struct {
|
||||
rc io.ReadCloser
|
||||
buff *bytes.Buffer
|
||||
f *FileResponse
|
||||
originalReader io.ReadCloser
|
||||
buffer *bytes.Buffer
|
||||
rileResponse *FileResponse
|
||||
cacheKey string
|
||||
cache cache.SetGetKey
|
||||
hasErr bool
|
||||
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,9 +107,9 @@ func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey,
|
|||
}
|
||||
|
||||
return &writeCacheReader{
|
||||
rc: r,
|
||||
buff: bytes.NewBuffer(make([]byte, 0)),
|
||||
f: &f,
|
||||
originalReader: r,
|
||||
buffer: bytes.NewBuffer(make([]byte, 0)),
|
||||
rileResponse: &f,
|
||||
cache: cache,
|
||||
cacheKey: cacheKey,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue