github.com/aclisp/heapster@v0.19.2-0.20160613100040-51756f899a96/Godeps/_workspace/src/k8s.io/kubernetes/pkg/apis/componentconfig/helpers.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package componentconfig 18 19 import ( 20 "fmt" 21 "net" 22 23 utilnet "k8s.io/kubernetes/pkg/util/net" 24 ) 25 26 // used for validating command line opts 27 // TODO(mikedanese): remove these when we remove command line flags 28 29 type IPVar struct { 30 Val *string 31 } 32 33 func (v IPVar) Set(s string) error { 34 if net.ParseIP(s) == nil { 35 return fmt.Errorf("%q is not a valid IP address", s) 36 } 37 if v.Val == nil { 38 // it's okay to panic here since this is programmer error 39 panic("the string pointer passed into IPVar should not be nil") 40 } 41 *v.Val = s 42 return nil 43 } 44 45 func (v IPVar) String() string { 46 if v.Val == nil { 47 return "" 48 } 49 return *v.Val 50 } 51 52 func (v IPVar) Type() string { 53 return "ip" 54 } 55 56 func (m *ProxyMode) Set(s string) error { 57 *m = ProxyMode(s) 58 return nil 59 } 60 61 func (m *ProxyMode) String() string { 62 if m != nil { 63 return string(*m) 64 } 65 return "" 66 } 67 68 func (m *ProxyMode) Type() string { 69 return "ProxyMode" 70 } 71 72 type PortRangeVar struct { 73 Val *string 74 } 75 76 func (v PortRangeVar) Set(s string) error { 77 if _, err := utilnet.ParsePortRange(s); err != nil { 78 return fmt.Errorf("%q is not a valid port range: %v", s, err) 79 } 80 if v.Val == nil { 81 // it's okay to panic here since this is programmer error 82 panic("the string pointer passed into PortRangeVar should not be nil") 83 } 84 *v.Val = s 85 return nil 86 } 87 88 func (v PortRangeVar) String() string { 89 if v.Val == nil { 90 return "" 91 } 92 return *v.Val 93 } 94 95 func (v PortRangeVar) Type() string { 96 return "port-range" 97 }