-
Notifications
You must be signed in to change notification settings - Fork 191
Closed
Description
Problem Description
The current implementation in pkg/deploy/envParams.go
uses strings.SplitN
to parse key=value pairs from environment files:
parts := strings.SplitN(line, "=", 2)
if len(parts) == 2 {
paramsEnvMap[parts[0]] = parts[1]
}
Proposed Improvement
Since Go 1.18, the strings.Cut
function provides a more idiomatic and cleaner way to handle this exact use case:
key, value, found := strings.Cut(line, "=")
if found {
paramsEnvMap[key] = value
}
Benefits
- More idiomatic:
strings.Cut
is specifically designed for the "split at first delimiter" use case - Clearer intent: The function name and return values explicitly communicate the operation
- Simpler code: Eliminates the need for array indexing and length checking
- Better readability: The
found
boolean makes the control flow more explicit
Additional Context
This improvement was identified during a discussion about environment file parsing alignment between opendatahub-operator and opendatahub-io/notebooks repositories. Both repositories handle key=value parsing, and using strings.Cut
would be a cleaner approach.
Acceptance Criteria
- Replace
strings.SplitN(line, "=", 2)
with `strings.Cut(line, "=")" in envParams.go - Update the conditional logic to use the
found
boolean - Ensure tests pass with the new implementation
- Verify no regression in functionality
References
- Related discussion: Improve sed pattern in check-params-env.sh to match variable names up to first '=' character notebooks#1785 (comment)
- Go strings.Cut documentation: https://pkg.go.dev/strings#Cut
- Requested by: @jiridanek
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Done