github.com/xiaobinqt/libcompose@v1.1.0/docker/client/client_factory.go (about)

     1  package client
     2  
     3  import (
     4  	"github.com/docker/docker/client"
     5  	"github.com/xiaobinqt/libcompose/project"
     6  )
     7  
     8  // Factory is a factory to create docker clients.
     9  type Factory 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 project.Service) client.APIClient
    14  }
    15  
    16  type defaultFactory struct {
    17  	client client.APIClient
    18  }
    19  
    20  // NewDefaultFactory creates and returns the default client factory that uses
    21  // github.com/docker/docker client.
    22  func NewDefaultFactory(opts Options) (Factory, error) {
    23  	client, err := Create(opts)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  
    28  	return &defaultFactory{
    29  		client: client,
    30  	}, nil
    31  }
    32  
    33  func (s *defaultFactory) Create(service project.Service) client.APIClient {
    34  	return s.client
    35  }