From fd4d58263c533087bfe12b1f8f7fdf70ab7e4d85 Mon Sep 17 00:00:00 2001 From: Sumeet Rai Date: Wed, 13 Nov 2024 16:04:09 +0530 Subject: [PATCH] fixed lint --- plugins/internal/tengoutil/secure_script.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/internal/tengoutil/secure_script.go b/plugins/internal/tengoutil/secure_script.go index 7ca121df..df953564 100644 --- a/plugins/internal/tengoutil/secure_script.go +++ b/plugins/internal/tengoutil/secure_script.go @@ -1,9 +1,11 @@ package tengoutil import ( + "context" "fmt" "io" "net/http" + "time" "github.com/d5/tengo/v2" "github.com/d5/tengo/v2/stdlib" @@ -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{