Skip to content

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

zhengkunwang223
Copy link
Member

Refs #8442

Copy link

f2c-ci-robot bot commented Apr 22, 2025

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.

Copy link

f2c-ci-robot bot commented Apr 22, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from zhengkunwang223. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

}

proxyConfig.ProxyPass = location.ProxyPass
proxyConfig.Cache = location.Cache
if location.CacheTime > 0 {
Copy link
Member

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:

  1. Initialization of Variables: The var statement is used to declare multiple variables (location, ok) at once, which makes the code cleaner.

  2. 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.

  3. 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 to interface{} since buserr.New() returns an interface{}.

  4. Variable Names: Make sure all variable names follow Go naming conventions (e.g., start with lowercase).

  5. 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants