Skip to content

Commit

Permalink
fixed lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumeet Rai committed Nov 13, 2024
1 parent 2dd9309 commit fd4d582
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions plugins/internal/tengoutil/secure_script.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package tengoutil

import (
"context"
"fmt"
"io"
"net/http"
"time"

"github.com/d5/tengo/v2"
"github.com/d5/tengo/v2/stdlib"
Expand Down Expand Up @@ -49,15 +51,22 @@ func createHTTPModule() map[string]tengo.Object {
return nil, fmt.Errorf("expected argument 1 (URL) to be a string")
}

resp, err := http.Get(url)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return &tengo.Error{Value: &tengo.String{Value: err.Error()}}, nil
return nil, err
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
return &tengo.Error{Value: &tengo.String{Value: err.Error()}}, nil
return nil, err
}

return &tengo.Map{
Expand Down

0 comments on commit fd4d582

Please sign in to comment.