Skip to content

Instantly share code, notes, and snippets.

@yudai
Created March 22, 2017 21:58
Show Gist options
  • Save yudai/b1aaf38ed9bbcc1d3717aa853018b811 to your computer and use it in GitHub Desktop.
Save yudai/b1aaf38ed9bbcc1d3717aa853018b811 to your computer and use it in GitHub Desktop.
custom factory
package somepackage
import (
"github.com/docker/docker/client"
libcomposeclient "github.com/docker/libcompose/docker/client"
"github.com/docker/libcompose/project"
)
type clientFactory struct {
client *client.Client
}
func newClientFactory() (*clientFactory, error) {
apiClient, err := libcomposeclient.Create(libcomposeclient.Options{})
if err != nil {
return nil, err
}
return &clientFactory{
client: apiClient.(*client.Client), // to get Close() accessible
}, nil
}
func (s *clientFactory) Create(service project.Service) client.APIClient {
return s.client
}
func (s *clientFactory) Close() {
s.client.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment