use switch case, move defers up

This commit is contained in:
feederbox826 2026-04-29 18:10:25 -04:00
parent 4fe6eedf58
commit 2205fb3987
No known key found for this signature in database
GPG key ID: 82F297A12EBB8A57

View file

@ -30,11 +30,10 @@ const scrapeDefaultSleep = time.Second * 2
func loadURL(ctx context.Context, loadURL string, client *http.Client, def Definition, globalConfig GlobalConfig) (io.Reader, error) {
driverOptions := def.DriverOptions
if driverOptions != nil {
if driverOptions.UseCDP {
// get the page using chrome dp
switch {
case driverOptions.UseCDP:
return urlFromCDP(ctx, loadURL, *driverOptions, globalConfig)
} else if driverOptions.UseSurf {
// get the page using surf
case driverOptions.UseSurf:
return urlFromSurf(ctx, loadURL, def, globalConfig)
}
}
@ -78,12 +77,11 @@ func loadURL(ctx context.Context, loadURL string, client *http.Client, def Defin
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return nil, fmt.Errorf("http error %d:%s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
@ -131,13 +129,11 @@ func urlFromSurf(ctx context.Context, loadURL string, def Definition, globalConf
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return nil, fmt.Errorf("http error %d:%s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err