multiple
This commit is contained in:
@@ -14,7 +14,8 @@ import (
|
||||
|
||||
// Client is the client for communicating with the daemon
|
||||
type Client struct {
|
||||
serverURL string
|
||||
serverURL string
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
// Command represents a command sent from the client to the daemon
|
||||
@@ -34,12 +35,15 @@ type Response struct {
|
||||
func NewClient(host string, port int) *Client {
|
||||
return &Client{
|
||||
serverURL: fmt.Sprintf("http://%s:%d", host, port),
|
||||
httpClient: &http.Client{
|
||||
Timeout: 60 * time.Second, // 60 second timeout for long operations
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// CheckStatus checks if the daemon is running
|
||||
func (c *Client) CheckStatus() (bool, error) {
|
||||
resp, err := http.Get(c.serverURL + "/status")
|
||||
resp, err := c.httpClient.Get(c.serverURL + "/status")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -174,7 +178,7 @@ func (c *Client) SendCommand(action string, params map[string]string) (*Response
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := http.Post(c.serverURL+"/command", "application/json", bytes.NewBuffer(jsonData))
|
||||
resp, err := c.httpClient.Post(c.serverURL+"/command", "application/json", bytes.NewBuffer(jsonData))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user