2018-02-05 16:05:59 -05:00
|
|
|
package opts // import "github.com/docker/docker/opts"
|
2015-02-11 14:21:38 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2019-08-05 10:37:47 -04:00
|
|
|
units "github.com/docker/go-units"
|
2015-02-11 14:21:38 -05:00
|
|
|
)
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// UlimitOpt defines a map of Ulimits
|
2015-02-11 14:21:38 -05:00
|
|
|
type UlimitOpt struct {
|
2015-12-21 15:06:46 -05:00
|
|
|
values *map[string]*units.Ulimit
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// NewUlimitOpt creates a new UlimitOpt
|
2015-12-21 15:06:46 -05:00
|
|
|
func NewUlimitOpt(ref *map[string]*units.Ulimit) *UlimitOpt {
|
2015-05-05 00:18:28 -04:00
|
|
|
if ref == nil {
|
2015-12-21 15:06:46 -05:00
|
|
|
ref = &map[string]*units.Ulimit{}
|
2015-05-05 00:18:28 -04:00
|
|
|
}
|
2015-02-11 14:21:38 -05:00
|
|
|
return &UlimitOpt{ref}
|
|
|
|
}
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// Set validates a Ulimit and sets its name as a key in UlimitOpt
|
2015-02-11 14:21:38 -05:00
|
|
|
func (o *UlimitOpt) Set(val string) error {
|
2015-12-21 15:06:46 -05:00
|
|
|
l, err := units.ParseUlimit(val)
|
2015-02-11 14:21:38 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
(*o.values)[l.Name] = l
|
2015-02-11 14:21:38 -05:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// String returns Ulimit values as a string.
|
2015-02-11 14:21:38 -05:00
|
|
|
func (o *UlimitOpt) String() string {
|
|
|
|
var out []string
|
2015-05-05 00:18:28 -04:00
|
|
|
for _, v := range *o.values {
|
2015-02-11 14:21:38 -05:00
|
|
|
out = append(out, v.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%v", out)
|
|
|
|
}
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// GetList returns a slice of pointers to Ulimits.
|
2015-12-21 15:06:46 -05:00
|
|
|
func (o *UlimitOpt) GetList() []*units.Ulimit {
|
|
|
|
var ulimits []*units.Ulimit
|
2015-05-05 00:18:28 -04:00
|
|
|
for _, v := range *o.values {
|
2015-02-11 14:21:38 -05:00
|
|
|
ulimits = append(ulimits, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ulimits
|
|
|
|
}
|
2016-05-31 19:49:32 -04:00
|
|
|
|
|
|
|
// Type returns the option type
|
|
|
|
func (o *UlimitOpt) Type() string {
|
|
|
|
return "ulimit"
|
|
|
|
}
|
2017-04-12 03:26:42 -04:00
|
|
|
|
|
|
|
// NamedUlimitOpt defines a named map of Ulimits
|
|
|
|
type NamedUlimitOpt struct {
|
|
|
|
name string
|
|
|
|
UlimitOpt
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ NamedOption = &NamedUlimitOpt{}
|
|
|
|
|
|
|
|
// NewNamedUlimitOpt creates a new NamedUlimitOpt
|
|
|
|
func NewNamedUlimitOpt(name string, ref *map[string]*units.Ulimit) *NamedUlimitOpt {
|
|
|
|
if ref == nil {
|
|
|
|
ref = &map[string]*units.Ulimit{}
|
|
|
|
}
|
|
|
|
return &NamedUlimitOpt{
|
|
|
|
name: name,
|
|
|
|
UlimitOpt: *NewUlimitOpt(ref),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the option name
|
|
|
|
func (o *NamedUlimitOpt) Name() string {
|
|
|
|
return o.name
|
|
|
|
}
|