mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-15 09:01:31 +00:00
chore: use strings.Cut
This commit is contained in:
@@ -3499,11 +3499,11 @@ func resolvePublicPoolFlags(source, poolRange, bindBridge, gateway, defaultBindB
|
||||
if gateway == "" {
|
||||
return "", "", "", "", fmt.Errorf("--external-gateway is required with --external-source=static")
|
||||
}
|
||||
parts := strings.SplitN(poolRange, "-", 2)
|
||||
if len(parts) != 2 || net.ParseIP(parts[0]) == nil || net.ParseIP(parts[1]) == nil {
|
||||
var ok bool
|
||||
start, end, ok = strings.Cut(poolRange, "-")
|
||||
if !ok || net.ParseIP(start) == nil || net.ParseIP(end) == nil {
|
||||
return "", "", "", "", fmt.Errorf("--external-pool must be start-end IPs (e.g., 192.168.1.150-192.168.1.250), got: %s", poolRange)
|
||||
}
|
||||
start, end = parts[0], parts[1]
|
||||
default:
|
||||
return "", "", "", "", fmt.Errorf("--external-source must be 'static' or 'dhcp', got: %s", source)
|
||||
}
|
||||
|
||||
@@ -438,14 +438,10 @@ func parseWeightsS3URI(uri string) (bucket, prefix string, err error) {
|
||||
if trimmed == uri {
|
||||
return "", "", fmt.Errorf("invalid --s3-uri %q: expected s3://bucket/prefix", uri)
|
||||
}
|
||||
parts := strings.SplitN(trimmed, "/", 2)
|
||||
bucket = parts[0]
|
||||
bucket, prefix, _ = strings.Cut(trimmed, "/")
|
||||
if bucket == "" {
|
||||
return "", "", fmt.Errorf("invalid --s3-uri %q: missing bucket", uri)
|
||||
}
|
||||
if len(parts) == 2 {
|
||||
prefix = parts[1]
|
||||
}
|
||||
if prefix != "" && !strings.HasSuffix(prefix, "/") {
|
||||
prefix += "/"
|
||||
}
|
||||
|
||||
@@ -114,9 +114,7 @@ func (m *Model) decodeErrorCode(body []byte) (string, error) {
|
||||
if separator := strings.LastIndex(code, "#"); separator >= 0 {
|
||||
code = code[separator+1:]
|
||||
}
|
||||
if separator := strings.Index(code, ":"); separator >= 0 {
|
||||
code = code[:separator]
|
||||
}
|
||||
code, _, _ = strings.Cut(code, ":")
|
||||
if code == "" {
|
||||
return "", fmt.Errorf("JSON error envelope has no code")
|
||||
}
|
||||
|
||||
@@ -135,9 +135,7 @@ func DecodeRequestResult(service Service, status int, header http.Header, body [
|
||||
}
|
||||
|
||||
func trimErrorCode(code string) string {
|
||||
if separator := strings.Index(code, ":"); separator >= 0 {
|
||||
code = code[:separator]
|
||||
}
|
||||
code, _, _ = strings.Cut(code, ":")
|
||||
if separator := strings.LastIndex(code, "#"); separator >= 0 {
|
||||
code = code[separator+1:]
|
||||
}
|
||||
|
||||
@@ -109,11 +109,9 @@ func GatewayHTTPClient(caPath string) (*http.Client, error) {
|
||||
// HostFromImage returns the host[:port] portion of an image ref or URL. It strips
|
||||
// any scheme and trims at the first path separator.
|
||||
func HostFromImage(image string) string {
|
||||
if i := strings.Index(image, "://"); i >= 0 {
|
||||
image = image[i+3:]
|
||||
if _, rest, ok := strings.Cut(image, "://"); ok {
|
||||
image = rest
|
||||
}
|
||||
if i := strings.IndexByte(image, '/'); i >= 0 {
|
||||
image = image[:i]
|
||||
}
|
||||
return image
|
||||
host, _, _ := strings.Cut(image, "/")
|
||||
return host
|
||||
}
|
||||
|
||||
@@ -42,9 +42,7 @@ func (r *TOMLVersionReader) ReadVersion(path string) (int, error) {
|
||||
}
|
||||
|
||||
// Handle "1.0" style — take the integer part before the dot.
|
||||
if idx := strings.Index(raw, "."); idx >= 0 {
|
||||
raw = raw[:idx]
|
||||
}
|
||||
raw, _, _ = strings.Cut(raw, ".")
|
||||
|
||||
v, err := strconv.Atoi(raw)
|
||||
if err != nil {
|
||||
|
||||
@@ -65,11 +65,11 @@ func DiscoverNanoInstanceType(t *testing.T, fx *Fixture) (instanceType, arch str
|
||||
if err != nil {
|
||||
t.Fatalf("DiscoverNanoInstanceType: %v", err)
|
||||
}
|
||||
parts := strings.SplitN(combined, "|", 2)
|
||||
if len(parts) != 2 {
|
||||
instanceType, arch, ok := strings.Cut(combined, "|")
|
||||
if !ok {
|
||||
t.Fatalf("DiscoverNanoInstanceType: malformed memo value %q", combined)
|
||||
}
|
||||
return parts[0], parts[1]
|
||||
return instanceType, arch
|
||||
}
|
||||
|
||||
// DiscoverUbuntuAMI returns the AMI ID for the architecture-appropriate Ubuntu
|
||||
|
||||
Reference in New Issue
Block a user