lock caller

This commit is contained in:
mr
2026-04-13 15:08:06 +02:00
parent d7b2ef6ae1
commit a653f9495b

View File

@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
"sync"
) )
// HTTP Method Enum defines the different methods that can be used to interact with the HTTP server // HTTP Method Enum defines the different methods that can be used to interact with the HTTP server
@@ -57,7 +58,8 @@ type HTTPCallerITF interface {
type HTTPCaller struct { type HTTPCaller struct {
URLS map[DataType]map[METHOD]string // Map of the different methods and their urls URLS map[DataType]map[METHOD]string // Map of the different methods and their urls
Disabled bool // Disabled flag Disabled bool // Disabled flag
LastResults map[string]interface{} // Used to store information regarding the last execution of a given method on a given data type Mu sync.RWMutex
LastResults map[string]interface{} // Used to store information regarding the last execution of a given method on a given data type
} }
// NewHTTPCaller creates a new instance of the HTTP Caller // NewHTTPCaller creates a new instance of the HTTP Caller
@@ -217,6 +219,8 @@ func (caller *HTTPCaller) CallForm(method string, url string, subpath string,
} }
func (caller *HTTPCaller) StoreResp(resp *http.Response) error { func (caller *HTTPCaller) StoreResp(resp *http.Response) error {
caller.Mu.Lock()
defer caller.Mu.Unlock()
caller.LastResults = make(map[string]interface{}) caller.LastResults = make(map[string]interface{})
caller.LastResults["header"] = resp.Header caller.LastResults["header"] = resp.Header
caller.LastResults["code"] = resp.StatusCode caller.LastResults["code"] = resp.StatusCode