Skip to content

Commit

Permalink
refactor(pkg,agent): remove code duplication when creating new agent
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybarreto authored and gustavosbarreto committed Sep 6, 2023
1 parent 8f75f5e commit 352dc1f
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,11 @@ type Agent struct {

// NewAgent creates a new agent instance.
func NewAgent(address string, tenantID string, privateKey string) (*Agent, error) {
if address == "" {
return nil, errors.New("address is empty")
}

addr, err := url.Parse(address)
if err != nil {
return nil, errors.Wrap(err, "failed to parse address")
}

if tenantID == "" {
return nil, errors.New("tenantID is empty")
}

if privateKey == "" {
return nil, errors.New("privateKey is empty")
}

a := &Agent{
config: &Config{
TenantID: tenantID,
ServerAddress: address,
PrivateKey: privateKey,
},
serverAddress: addr,
}

return a, nil
return NewAgentWithConfig(&Config{
ServerAddress: address,
TenantID: tenantID,
PrivateKey: privateKey,
})
}

// NewAgentWithConfig creates a new agent instance with a custom configuration.
Expand Down

0 comments on commit 352dc1f

Please sign in to comment.