Skip to content
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

net/ghttp: Server Domain if is empty str, bind handler pattern will add @ which is not expect #4100

Open
elonnzhang opened this issue Jan 7, 2025 · 0 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@elonnzhang
Copy link

Go version

go version go1.22.6 linux/amd64

GoFrame version

v2.7.1

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

s.Domain(strings.Join(config.AppConfig().Server.Domains, ",")).Group()
if config.AppConfig().Server.Domains is empty, strings.Join(config.AppConfig().Server.Domains, ",") will be a empty str (""),
and in Bind logic

// Domain creates and returns a domain object for management for one or more domains.
func (s *Server) Domain(domains string) *Domain {
	d := &Domain{
		server:  s,
		domains: make(map[string]struct{}),
	}
	for _, v := range strings.Split(domains, ",") {
		d.domains[strings.TrimSpace(v)] = struct{}{}
	}
	return d
}

// BindHandler binds the handler for the specified pattern.
func (d *Domain) BindHandler(pattern string, handler interface{}) {
	for domain := range d.domains {
		d.server.BindHandler(pattern+"@"+domain, handler)
	}
}

for range domains, actually d.server.BindHandler(pattern+"@"+"", handler)
eg:
default | :8008 | POST | /api/db/sql/queryStream@

What did you see happen?

image

What did you expect to see?

if domains is emtpy, this domain setting is not needed.
binding url is default | :8008 | POST | /api/db/sql/queryStream not queryStream@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

No branches or pull requests

1 participant