fixed curl problems again

This commit is contained in:
milarin 2023-03-07 18:54:53 +01:00
parent 799d8d5dee
commit 2787b57189

29
curl.go
View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"os/exec" "os/exec"
"git.milar.in/milarin/adverr"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
) )
@ -26,23 +25,11 @@ func (api *Api) GetWithCookie(ctx context.Context, url string) (*goquery.Documen
if err != nil { if err != nil {
return nil, ErrCurlRequestFailed.Wrap(err, url) return nil, ErrCurlRequestFailed.Wrap(err, url)
} }
defer stdout.Close()
stderr, err := curl.StderrPipe()
if err != nil {
return nil, ErrCurlRequestFailed.Wrap(err, url)
}
defer stderr.Close()
if err := curl.Start(); err != nil { if err := curl.Start(); err != nil {
return nil, ErrCurlRequestFailed.Wrap(err, url) return nil, ErrCurlRequestFailed.Wrap(err, url)
} }
defer curl.Wait()
go func() {
if err := curl.Wait(); err != nil {
adverr.Println(ErrCurlRequestFailed.Wrap(err, url))
}
}()
r, err := gzip.NewReader(stdout) r, err := gzip.NewReader(stdout)
if err != nil { if err != nil {
@ -63,23 +50,11 @@ func (api *Api) Get(ctx context.Context, url string) (*goquery.Document, error)
if err != nil { if err != nil {
return nil, ErrCurlRequestFailed.Wrap(err, url) return nil, ErrCurlRequestFailed.Wrap(err, url)
} }
defer stdout.Close()
stderr, err := curl.StderrPipe()
if err != nil {
return nil, ErrCurlRequestFailed.Wrap(err, url)
}
defer stderr.Close()
if err := curl.Start(); err != nil { if err := curl.Start(); err != nil {
return nil, ErrCurlRequestFailed.Wrap(err, url) return nil, ErrCurlRequestFailed.Wrap(err, url)
} }
defer curl.Wait()
go func() {
if err := curl.Wait(); err != nil {
adverr.Println(ErrCurlRequestFailed.Wrap(err, url))
}
}()
r, err := gzip.NewReader(stdout) r, err := gzip.NewReader(stdout)
if err != nil { if err != nil {