github.com/alexandrev/docker@v1.9.0/opts/ulimit.go (about)

     1  package opts
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/docker/docker/pkg/ulimit"
     7  )
     8  
     9  // UlimitOpt defines a map of Ulimits
    10  type UlimitOpt struct {
    11  	values *map[string]*ulimit.Ulimit
    12  }
    13  
    14  // NewUlimitOpt creates a new UlimitOpt
    15  func NewUlimitOpt(ref *map[string]*ulimit.Ulimit) *UlimitOpt {
    16  	if ref == nil {
    17  		ref = &map[string]*ulimit.Ulimit{}
    18  	}
    19  	return &UlimitOpt{ref}
    20  }
    21  
    22  // Set validates a Ulimit and sets its name as a key in UlimitOpt
    23  func (o *UlimitOpt) Set(val string) error {
    24  	l, err := ulimit.Parse(val)
    25  	if err != nil {
    26  		return err
    27  	}
    28  
    29  	(*o.values)[l.Name] = l
    30  
    31  	return nil
    32  }
    33  
    34  // String returns Ulimit values as a string.
    35  func (o *UlimitOpt) String() string {
    36  	var out []string
    37  	for _, v := range *o.values {
    38  		out = append(out, v.String())
    39  	}
    40  
    41  	return fmt.Sprintf("%v", out)
    42  }
    43  
    44  // GetList returns a slice of pointers to Ulimits.
    45  func (o *UlimitOpt) GetList() []*ulimit.Ulimit {
    46  	var ulimits []*ulimit.Ulimit
    47  	for _, v := range *o.values {
    48  		ulimits = append(ulimits, v)
    49  	}
    50  
    51  	return ulimits
    52  }