github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/configuration_map.go (about) 1 /* 2 Copyright 2014 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 util 18 19 import ( 20 "fmt" 21 "sort" 22 "strings" 23 ) 24 25 type ConfigurationMap map[string]string 26 27 func (m *ConfigurationMap) String() string { 28 pairs := []string{} 29 for k, v := range *m { 30 pairs = append(pairs, fmt.Sprintf("%s=%s", k, v)) 31 } 32 sort.Strings(pairs) 33 return strings.Join(pairs, ",") 34 } 35 36 func (m *ConfigurationMap) Set(value string) error { 37 for _, s := range strings.Split(value, ",") { 38 if len(s) == 0 { 39 continue 40 } 41 arr := strings.SplitN(s, "=", 2) 42 if len(arr) == 2 { 43 (*m)[strings.TrimSpace(arr[0])] = strings.TrimSpace(arr[1]) 44 } else { 45 (*m)[strings.TrimSpace(arr[0])] = "" 46 } 47 } 48 return nil 49 } 50 51 func (*ConfigurationMap) Type() string { 52 return "mapStringString" 53 }