Skip to content

Commit

Permalink
Add headers to time sync request (#20)
Browse files Browse the repository at this point in the history
* no need for duration cast

* set headers on time request

Signed-off-by: dimagolomozy <[email protected]>

* use const

---------

Signed-off-by: dimagolomozy <[email protected]>
  • Loading branch information
DimaGolomozy authored Apr 18, 2024
1 parent 5609d41 commit 6f6e1cc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
// SendRequest send logs data to Coralogix server
func SendRequest(Bulk *Bulk) int {
client := &http.Client{
Timeout: time.Duration(time.Duration(HTTPTimeout) * time.Second),
Timeout: time.Duration(HTTPTimeout) * time.Second,
}

for Attempt := 1; uint(Attempt) <= HTTPSendRetryCount; Attempt++ {
DebugLogger.Println("About to send bulk to Coralogix server. Attempt number:", Attempt)

request, err := http.NewRequest("POST", LogURL, bytes.NewBuffer(Bulk.ToJSON()))
request, err := http.NewRequest(http.MethodPost, LogURL, bytes.NewBuffer(Bulk.ToJSON()))
if err != nil {
DebugLogger.Println("Can't create HTTP request:", err)
continue
Expand Down Expand Up @@ -48,11 +48,17 @@ func GetTimeSync() (bool, float64) {
DebugLogger.Println("Syncing time with Coralogix server...")

client := &http.Client{
Timeout: time.Duration(time.Duration(TimeDelayTimeout) * time.Second),
Timeout: time.Duration(TimeDelayTimeout) * time.Second,
}

response, err := client.Get(TimeDeltaURL)
request, err := http.NewRequest(http.MethodGet, TimeDeltaURL, nil)
if err != nil {
DebugLogger.Println("Can't create HTTP request:", err)
return false, 0
}
request.Header = Headers

response, err := client.Do(request)
if err != nil {
DebugLogger.Println("Can't execute HTTP request:", err)
return false, 0
Expand Down

0 comments on commit 6f6e1cc

Please sign in to comment.