client_factory.go 932 B

123456789101112131415161718192021222324252627282930313233343536
  1. package project
  2. import (
  3. "github.com/docker/engine-api/client"
  4. composeclient "github.com/docker/libcompose/docker/client"
  5. )
  6. // ClientFactory is a factory to create docker clients.
  7. type ClientFactory interface {
  8. // Create constructs a Docker client for the given service. The passed in
  9. // config may be nil in which case a generic client for the project should
  10. // be returned.
  11. Create(service Service) client.APIClient
  12. }
  13. type defaultClientFactory struct {
  14. client client.APIClient
  15. }
  16. // NewDefaultClientFactory creates and returns the default client factory that uses
  17. // github.com/docker/engine-api client.
  18. func NewDefaultClientFactory(opts composeclient.Options) (ClientFactory, error) {
  19. client, err := composeclient.Create(opts)
  20. if err != nil {
  21. return nil, err
  22. }
  23. return &defaultClientFactory{
  24. client: client,
  25. }, nil
  26. }
  27. func (s *defaultClientFactory) Create(service Service) client.APIClient {
  28. return s.client
  29. }