mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00

I want to use the Addrs type in another experimental proxy that I am implementing. Pull it out into a separate package.
40 lines
633 B
Go
40 lines
633 B
Go
package flags
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
const (
|
|
ProxyValueOff = "off"
|
|
ProxyValueReadonly = "readonly"
|
|
ProxyValueOn = "on"
|
|
)
|
|
|
|
var (
|
|
ProxyValues = []string{
|
|
ProxyValueOff,
|
|
ProxyValueReadonly,
|
|
ProxyValueOn,
|
|
}
|
|
)
|
|
|
|
// ProxyFlag implements the flag.Value interface.
|
|
type Proxy string
|
|
|
|
// Set verifies the argument to be a valid member of proxyFlagValues
|
|
// before setting the underlying flag value.
|
|
func (pf *Proxy) Set(s string) error {
|
|
for _, v := range ProxyValues {
|
|
if s == v {
|
|
*pf = Proxy(s)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
return errors.New("invalid value")
|
|
}
|
|
|
|
func (pf *Proxy) String() string {
|
|
return string(*pf)
|
|
}
|