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

Cleanup the usage of URLs into its own type so we don't have to use a FlagValue everywhere we have a list of URLs.
37 lines
625 B
Go
37 lines
625 B
Go
package flags
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/coreos/etcd/pkg/types"
|
|
)
|
|
|
|
type URLsValue types.URLs
|
|
|
|
// Set parses a command line set of URLs formatted like:
|
|
// http://127.0.0.1:7001,http://10.1.1.2:80
|
|
func (us *URLsValue) Set(s string) error {
|
|
strs := strings.Split(s, ",")
|
|
nus, err := types.NewURLs(strs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*us = URLsValue(nus)
|
|
return nil
|
|
}
|
|
|
|
func (us *URLsValue) String() string {
|
|
all := make([]string, len(*us))
|
|
for i, u := range *us {
|
|
all[i] = u.String()
|
|
}
|
|
return strings.Join(all, ",")
|
|
}
|
|
|
|
func NewURLsValue(init string) *URLsValue {
|
|
v := &URLsValue{}
|
|
v.Set(init)
|
|
return v
|
|
}
|