backend.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package example
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "github.com/docker/api/backend"
  7. "github.com/docker/api/containers"
  8. )
  9. type containerService struct{}
  10. func init() {
  11. backend.Register("example", "example", func(ctx context.Context) (interface{}, error) {
  12. return &containerService{}, nil
  13. })
  14. }
  15. func (cs *containerService) List(ctx context.Context) ([]containers.Container, error) {
  16. return []containers.Container{
  17. {
  18. ID: "id",
  19. Image: "nginx",
  20. },
  21. {
  22. ID: "1234",
  23. Image: "alpine",
  24. },
  25. }, nil
  26. }
  27. func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfig) error {
  28. fmt.Printf("Running container %q with name %q\n", r.Image, r.ID)
  29. return nil
  30. }
  31. func (cs *containerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error {
  32. fmt.Printf("Executing command %q on container %q", command, name)
  33. return nil
  34. }
  35. func (cs *containerService) Logs(ctx context.Context, containerName string, request containers.LogsRequest) error {
  36. fmt.Fprintf(request.Writer, "Following logs for container %q", containerName)
  37. return nil
  38. }