small restructuring in preparation for something

This commit is contained in:
Laptop
2024-12-23 18:57:32 +02:00
parent 8adb7a8b41
commit 491aa6028c
9 changed files with 148 additions and 125 deletions

41
lib/misc/init.go Normal file
View File

@@ -0,0 +1,41 @@
package misc
import (
"fmt"
"io"
"sync"
"github.com/maid-zone/soundcloak/lib/cfg"
"github.com/valyala/fasthttp"
)
var prpool = sync.Pool{
New: func() any {
return &ProxyReader{}
},
}
func AcquireProxyReader() *ProxyReader {
return prpool.Get().(*ProxyReader)
}
type ProxyReader struct {
Reader io.Reader
Resp *fasthttp.Response
}
func (pr *ProxyReader) Read(p []byte) (int, error) {
return pr.Reader.Read(p)
}
func (pr *ProxyReader) Close() error {
defer fasthttp.ReleaseResponse(pr.Resp)
defer prpool.Put(pr)
return pr.Resp.CloseBodyStream()
}
func Log(what ...any) {
if cfg.Debug {
fmt.Println(what...)
}
}