2 Copyright 2015 The Kubernetes Authors.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
22 "k8s.io/apimachinery/pkg/util/sets"
25 var validSchemes = sets.NewString("http", "https", "")
27 // SplitSchemeNamePort takes a string of the following forms:
28 // * "<name>", returns "", "<name>","", true
29 // * "<name>:<port>", returns "", "<name>","<port>",true
30 // * "<scheme>:<name>:<port>", returns "<scheme>","<name>","<port>",true
32 // Name must be non-empty or valid will be returned false.
33 // Scheme must be "http" or "https" if specified
34 // Port is returned as a string, and it is not required to be numeric (could be
35 // used for a named port, for example).
36 func SplitSchemeNamePort(id string) (scheme, name, port string, valid bool) {
37 parts := strings.Split(id, ":")
49 return "", "", "", false
52 if len(name) > 0 && validSchemes.Has(scheme) {
53 return scheme, name, port, true
55 return "", "", "", false
59 // JoinSchemeNamePort returns a string that specifies the scheme, name, and port:
62 // * "<scheme>:<name>:<port>"
63 // None of the parameters may contain a ':' character
65 // Scheme must be "", "http", or "https"
66 func JoinSchemeNamePort(scheme, name, port string) string {
68 // Must include three segments to specify scheme
69 return scheme + ":" + name + ":" + port
72 // Must include two segments to specify port
73 return name + ":" + port