Created
November 13, 2019 17:34
-
-
Save tangx/20a68167fca33237fa02891d10d6ce65 to your computer and use it in GitHub Desktop.
使用int位数判断特定类型的数据,例如端口
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "28080:80" | |
ports := strings.Split(s, ":") | |
p, err := strconv.ParseUint(ports[0], 10, 16) | |
if err != nil { | |
return nil, fmt.Errorf("invalid port %v", ports[0]) | |
} | |
port = uint16(p) | |
if len(ports) == 2 { | |
if isNodePort { | |
if port < 20000 || p > 40000 { | |
return nil, fmt.Errorf("Invalid value: %d: provided port is not in the valid range. The range of valid ports is 20000-40000", port) | |
} | |
} | |
p, err := strconv.ParseUint(ports[1], 10, 16) | |
if err != nil { | |
panic(fmt.Errorf("invalid target port %v", ports[1])) | |
} | |
targetPort = uint16(p) | |
} else { | |
targetPort = port | |
} |
Author
tangx
commented
Nov 13, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment