Skip to content

Commit

Permalink
fix: remove httpclient
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiomatavelli committed May 13, 2022
1 parent 4c819c3 commit f3b3a80
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions millennium.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ type Millennium struct {
// Server used to store the server address
ServerAddr string

// HTTP Client
HTTPClient *http.Client

// Client points to retryable http lib
client *retryablehttp.Client
Client *retryablehttp.Client

// Context
Context context.Context
Expand Down Expand Up @@ -125,15 +122,6 @@ func NewClient(ctx context.Context, server string, timeout time.Duration) (*Mill
return nil, errors.New("timeout is zero")
}

// // Parse server address
// url, err := url.Parse(server)
// if err != nil {
// return nil, fmt.Errorf("unable to parse server address: %w", err)
// }

// conn :=
// conn.Close()

m := &Millennium{
ServerAddr: server,
Context: ctx,
Expand All @@ -145,15 +133,14 @@ func NewClient(ctx context.Context, server string, timeout time.Duration) (*Mill
m.Context = context.Background()
}

m.client = m.setClient()
m.Client = m.setClient()

return m, nil
}

func (m *Millennium) setClient() *retryablehttp.Client {
client := retryablehttp.NewClient()
client.RetryMax = RetryMax
client.HTTPClient = m.HTTPClient

return client
}
Expand All @@ -167,11 +154,7 @@ func (m *Millennium) Login(username string, password string, authType AuthType)

// If AuthType equals NTLM then set client transport to ntlm negotiator
if authType == NTLM {
if m.HTTPClient == nil {
m.HTTPClient = &http.Client{}
}

m.HTTPClient.Transport = ntlmssp.Negotiator{
m.Client.HTTPClient.Transport = ntlmssp.Negotiator{
RoundTripper: &http.Transport{},
}
}
Expand Down Expand Up @@ -255,7 +238,7 @@ func (m *Millennium) sendRequest(request *retryablehttp.Request, response interf
request = request.WithContext(ctx)
defer cancel()

res, err := m.client.Do(request)
res, err := m.Client.Do(request)
if err != nil {
return fmt.Errorf("unable to send request: %w", err)
}
Expand Down

0 comments on commit f3b3a80

Please sign in to comment.