Fixed few memory leaks. Implement testing of the functionality.
This commit is contained in:
@@ -79,6 +79,10 @@ var (
|
||||
startTime time.Time
|
||||
health HealthStatus
|
||||
healthMux sync.RWMutex
|
||||
// HTTP client with timeout to prevent indefinite hangs
|
||||
httpClient = &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -460,7 +464,7 @@ func handleSocket(path string, data []byte, mode string) ([]byte, error) {
|
||||
|
||||
func readSource(src string) ([]byte, error) {
|
||||
if strings.HasPrefix(src, "http") {
|
||||
resp, err := http.Get(src)
|
||||
resp, err := httpClient.Get(src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -477,7 +481,7 @@ func readSource(src string) ([]byte, error) {
|
||||
|
||||
func writeDestination(dest string, data []byte) error {
|
||||
if strings.HasPrefix(dest, "http") {
|
||||
resp, err := http.Post(dest, "application/json", bytes.NewBuffer(data))
|
||||
resp, err := httpClient.Post(dest, "application/json", bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user