github.com/skippbox/kompose-origin@v0.0.0-20160524133224-16a9dca7bac2/project/client_factory.go (about)

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