Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Ability to set HTTP Client timeout #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion loggly.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Client struct {
// Token string.
Token string

Timeout time.Duration

// Default properties.
Defaults Message
buffer [][]byte
Expand Down Expand Up @@ -212,6 +214,11 @@ func (c *Client) Emergency(t string, props ...Message) error {
return c.Send(msg)
}

// SetTimeout for HTTP requests.
func (c *Client) SetTimeout(timeout time.Duration) {
c.Timeout = timeout
}

// Flush the buffered messages.
func (c *Client) Flush() error {
c.Lock()
Expand All @@ -226,7 +233,9 @@ func (c *Client) Flush() error {
c.buffer = nil
c.Unlock()

client := &http.Client{}
client := &http.Client{
Timeout: c.Timeout,
}
req, err := http.NewRequest("POST", c.Endpoint, bytes.NewBuffer(body))
if err != nil {
return err
Expand Down