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 {
|
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,10 +107,10 @@ 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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue