| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 | 
							- package run
 
- import (
 
- 	"fmt"
 
- 	"strconv"
 
- 	"strings"
 
- 	"github.com/docker/api/containers"
 
- )
 
- type runOpts struct {
 
- 	name    string
 
- 	publish []string
 
- }
 
- func toPorts(ports []string) ([]containers.Port, error) {
 
- 	var result []containers.Port
 
- 	for _, port := range ports {
 
- 		parts := strings.Split(port, ":")
 
- 		if len(parts) != 2 {
 
- 			return nil, fmt.Errorf("unable to parse ports %q", port)
 
- 		}
 
- 		source, err := strconv.Atoi(parts[0])
 
- 		if err != nil {
 
- 			return nil, err
 
- 		}
 
- 		destination, err := strconv.Atoi(parts[1])
 
- 		if err != nil {
 
- 			return nil, err
 
- 		}
 
- 		result = append(result, containers.Port{
 
- 			Source:      uint32(source),
 
- 			Destination: uint32(destination),
 
- 		})
 
- 	}
 
- 	return result, nil
 
- }
 
- func (r *runOpts) toContainerConfig(image string) (containers.ContainerConfig, error) {
 
- 	publish, err := toPorts(r.publish)
 
- 	if err != nil {
 
- 		return containers.ContainerConfig{}, err
 
- 	}
 
- 	return containers.ContainerConfig{
 
- 		ID:    r.name,
 
- 		Image: image,
 
- 		Ports: publish,
 
- 	}, nil
 
- }
 
 
  |