go.etcd.io/etcd@v3.3.27+incompatible/pkg/flags/urls.go (about) 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 15 package flags 16 17 import ( 18 "strings" 19 20 "github.com/coreos/etcd/pkg/types" 21 ) 22 23 type URLsValue types.URLs 24 25 // Set parses a command line set of URLs formatted like: 26 // http://127.0.0.1:2380,http://10.1.1.2:80 27 func (us *URLsValue) Set(s string) error { 28 strs := strings.Split(s, ",") 29 nus, err := types.NewURLs(strs) 30 if err != nil { 31 return err 32 } 33 34 *us = URLsValue(nus) 35 return nil 36 } 37 38 func (us *URLsValue) String() string { 39 all := make([]string, len(*us)) 40 for i, u := range *us { 41 all[i] = u.String() 42 } 43 return strings.Join(all, ",") 44 } 45 46 func NewURLsValue(init string) *URLsValue { 47 v := &URLsValue{} 48 if err := v.Set(init); err != nil { 49 plog.Panicf("new URLsValue should never fail: %v", err) 50 } 51 return v 52 }