Skip to content

Instantly share code, notes, and snippets.

@yudai
Created March 22, 2017 21:58
Show Gist options
  • Select an option

  • Save yudai/b1aaf38ed9bbcc1d3717aa853018b811 to your computer and use it in GitHub Desktop.

Select an option

Save yudai/b1aaf38ed9bbcc1d3717aa853018b811 to your computer and use it in GitHub Desktop.

Revisions

  1. yudai created this gist Mar 22, 2017.
    30 changes: 30 additions & 0 deletions client_factory.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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()
    }