-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix issue with errors when reverse proxy source text includes comments. #8444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
} | ||
|
||
proxyConfig.ProxyPass = location.ProxyPass | ||
proxyConfig.Cache = location.Cache | ||
if location.CacheTime > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code contains a few potential improvements and corrections:
-
Initialization of Variables: The
var
statement is used to declare multiple variables (location
,ok
) at once, which makes the code cleaner. -
Error Handling for Directives Iteration: Instead of using an explicit loop with
break
, you can use Go's short variable assignment within the condition to simplify error handling when no matching directive is found. -
Return Statement Consistency: Ensure that the return statements are consistent in terms of parameter names and types throughout the function. Currently, they only need to match up if you change the type from
[]request.WebsiteProxyConfig
tointerface{}
sincebuserr.New()
returns an interface{}. -
Variable Names: Make sure all variable names follow Go naming conventions (e.g., start with lowercase).
-
Comment Correction: Corrected the comment on this line "return nil, buserr.New("err")" to read "return nil, buserr.New("ErrConfigParse")".
Here's optimized version of your function based on these comments:
func (w WebsiteService) GetProxies(id uint) ([]request.WebsiteProxyConfig, error) {
config := w.getWebsiteConfig(id)
var (
location *components.Location
ok bool
)
directives := config.GetDirectives()
for _, directive := range directives {
if directive.GetName() == "location" && directive.(*components.Location).GetName() == "location" { // Assuming both have the same struct name
location, ok = directive.(*components.Location)
break
}
}
if !ok || location == nil {
return nil, buserr.New("ErrConfigParse")
}
proxyConfig.ProxyPass = location.ProxyPass
proxyConfig.Cache = location.Cache
if location.CacheTime > 0 {
// ... further processing
}
return []request.WebsiteProxyConfig{*proxyConfig}, nil
}
Make sure to adjust the struct field accesses according to your actual data structure. If there's any specific part of the data structure you'd like to ensure correctness about, feel free to mention it!
|
Refs #8442