urls.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2015 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package flags
  15. import (
  16. "strings"
  17. "github.com/coreos/etcd/pkg/types"
  18. )
  19. type URLsValue types.URLs
  20. // Set parses a command line set of URLs formatted like:
  21. // http://127.0.0.1:2380,http://10.1.1.2:80
  22. func (us *URLsValue) Set(s string) error {
  23. strs := strings.Split(s, ",")
  24. nus, err := types.NewURLs(strs)
  25. if err != nil {
  26. return err
  27. }
  28. *us = URLsValue(nus)
  29. return nil
  30. }
  31. func (us *URLsValue) String() string {
  32. all := make([]string, len(*us))
  33. for i, u := range *us {
  34. all[i] = u.String()
  35. }
  36. return strings.Join(all, ",")
  37. }
  38. func NewURLsValue(init string) *URLsValue {
  39. v := &URLsValue{}
  40. if err := v.Set(init); err != nil {
  41. plog.Panicf("new URLsValue should never fail: %v", err)
  42. }
  43. return v
  44. }