mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-25 16:44:01 +08:00
add timeout for http requests
This commit is contained in:
parent
afc0fa01b5
commit
a17173fa0f
1 changed files with 7 additions and 1 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gravitl/netmaker/logger"
|
"github.com/gravitl/netmaker/logger"
|
||||||
"github.com/gravitl/netmaker/models"
|
"github.com/gravitl/netmaker/models"
|
||||||
|
@ -25,6 +26,9 @@ import (
|
||||||
// LINUX_APP_DATA_PATH - linux path
|
// LINUX_APP_DATA_PATH - linux path
|
||||||
const LINUX_APP_DATA_PATH = "/etc/netmaker"
|
const LINUX_APP_DATA_PATH = "/etc/netmaker"
|
||||||
|
|
||||||
|
// HTTP_TIMEOUT - timeout in seconds for http requests
|
||||||
|
const HTTP_TIMEOUT = 30
|
||||||
|
|
||||||
// ListPorts - lists ports of WireGuard devices
|
// ListPorts - lists ports of WireGuard devices
|
||||||
func ListPorts() error {
|
func ListPorts() error {
|
||||||
wgclient, err := wgctrl.New()
|
wgclient, err := wgctrl.New()
|
||||||
|
@ -339,7 +343,9 @@ func API(data any, method, url, authorization string) (*http.Response, error) {
|
||||||
if authorization != "" {
|
if authorization != "" {
|
||||||
request.Header.Set("authorization", "Bearer "+authorization)
|
request.Header.Set("authorization", "Bearer "+authorization)
|
||||||
}
|
}
|
||||||
client := http.Client{}
|
client := http.Client{
|
||||||
|
Timeout: HTTP_TIMEOUT * time.Second,
|
||||||
|
}
|
||||||
return client.Do(request)
|
return client.Do(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue