mirror of
https://github.com/stashapp/stash.git
synced 2026-05-09 05:05:29 +02:00
use switch case, move defers up
This commit is contained in:
parent
4fe6eedf58
commit
2205fb3987
1 changed files with 5 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue