mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-11 14:19:38 +05:00
small restructuring in preparation for something
This commit is contained in:
41
lib/misc/init.go
Normal file
41
lib/misc/init.go
Normal 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...)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user