Skip to content

Commit

Permalink
refactor: Removed the singleton pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFaucherre committed Aug 8, 2023
1 parent 7408eb6 commit 2f88190
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
17 changes: 1 addition & 16 deletions api/orb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ import (
"fmt"
"io"
"os"
"sync"

"github.com/CircleCI-Public/circleci-cli/api"
"github.com/CircleCI-Public/circleci-cli/api/graphql"
"github.com/CircleCI-Public/circleci-cli/settings"
"github.com/pkg/errors"
)

var (
once sync.Once
client Client
clientError error
)

type clientVersion string

// ConfigResponse is a structure that matches the result of the GQL
Expand All @@ -33,15 +26,7 @@ type Client interface {
OrbQuery(configPath string, ownerId string) (*api.ConfigResponse, error)
}

func GetClient(config *settings.Config) (Client, error) {
once.Do(func() {
client, clientError = newClient(config)
})

return client, clientError
}

func newClient(config *settings.Config) (Client, error) {
func NewClient(config *settings.Config) (Client, error) {
gql := graphql.NewClient(config.HTTPClient, config.Host, config.Endpoint, config.Token, config.Debug)

clientVersion, err := detectClientVersion(gql)
Expand Down
4 changes: 2 additions & 2 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ func validateOrb(opts orbOptions, org orbOrgOptions) error {
return fmt.Errorf("failed to get the appropriate org-id: %s", err.Error())
}

client, err := orb.GetClient(opts.cfg)
client, err := orb.NewClient(opts.cfg)
if err != nil {
return errors.Wrap(err, "Getting orb client")
}
Expand All @@ -759,7 +759,7 @@ func processOrb(opts orbOptions, org orbOrgOptions) error {
return fmt.Errorf("failed to get the appropriate org-id: %s", err.Error())
}

client, err := orb.GetClient(opts.cfg)
client, err := orb.NewClient(opts.cfg)
if err != nil {
return errors.Wrap(err, "Getting orb client")
}
Expand Down

0 comments on commit 2f88190

Please sign in to comment.