Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added req as an interface to golang http client #581

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions api/services/methodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,23 @@ func (data UserServiceDataToCheck) StatusCodeUserExistsFunc() (bool, error) {
}
log.Printf("checking service %s for status code: %s\n", data.Service.Name, url)

resp, err := http.Get(url)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.Printf("error status code check: %s", err)
return false, fmt.Errorf("failed to send GET request: %w", err)
return false, err
}
log.Printf("status code for %s (%s): %d \n", data.Service.Name, url, resp.StatusCode)
defer resp.Body.Close()

resp, err := http.DefaultClient.Do(req)
if err != nil {
return false, err
}

// resp, err := http.Get(url)
// if err != nil {
// log.Printf("error status code check: %s", err)
// return false, fmt.Errorf("failed to send GET request: %w", err)
// }
// log.Printf("status code for %s (%s): %d \n", data.Service.Name, url, resp.StatusCode)
// defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
return true, nil
Expand Down
15 changes: 15 additions & 0 deletions api/services/req.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package services

import (
"io"
"net/http"
"time"
)

func httpClient() *http.Client {
client := &http.Client{Timeout: 10 * time.Second}
return client
}
func NewRequest(method string, url string, body io.Reader) (*http.Request, error) {
return http.NewRequest(method, url, body)
}
Loading