github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/runconfig/opts/ulimit.go (about) 1 package opts 2 3 import ( 4 "fmt" 5 6 "github.com/docker/go-units" 7 ) 8 9 // UlimitOpt defines a map of Ulimits 10 type UlimitOpt struct { 11 values *map[string]*units.Ulimit 12 } 13 14 // NewUlimitOpt creates a new UlimitOpt 15 func NewUlimitOpt(ref *map[string]*units.Ulimit) *UlimitOpt { 16 if ref == nil { 17 ref = &map[string]*units.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 := units.ParseUlimit(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() []*units.Ulimit { 46 var ulimits []*units.Ulimit 47 for _, v := range *o.values { 48 ulimits = append(ulimits, v) 49 } 50 51 return ulimits 52 } 53 54 // Type returns the option type 55 func (o *UlimitOpt) Type() string { 56 return "ulimit" 57 }