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

fix listen address parse #310

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions pkg/exporter/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,23 +295,20 @@ func (i *inspServer) createListener(cfg *InspServerConfig) (net.Listener, error)
}

rawAddr := cfg.Address
if !strings.Contains(rawAddr, "//") {
if !strings.Contains(rawAddr, "://") {
log.Infof("address contains no protocol part, use tcp:// by default")
rawAddr = "tcp://" + rawAddr
}

protocol := ""
addr := ""

u, err := url.Parse(rawAddr)
if err != nil {
return nil, fmt.Errorf("invalid address %s, valid format is [protocol://]addr[:port]", cfg.Address)
return nil, fmt.Errorf("invalid address %s, valid format is [protocol://]addr[:port]", rawAddr)
}
protocol = u.Scheme
protocol := u.Scheme
addr := ""
switch protocol {
case "unix":
// For Unix domain sockets, the path is in the opaque part
addr = strings.TrimPrefix(cfg.Address, "unix://")
addr = u.Path
if _, err = os.Stat(addr); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return nil, fmt.Errorf("failed stat sock file %s: %w", addr, err)
Expand All @@ -325,8 +322,7 @@ func (i *inspServer) createListener(cfg *InspServerConfig) (net.Listener, error)
_ = os.Remove(addr)
}
case "tcp":
host, port, _ := net.SplitHostPort(cfg.Address)
addr = fmt.Sprintf("%s:%s", host, port)
addr = u.Host
default:
return nil, fmt.Errorf("unsupported protocol %s, only `tcp` and 'unix' are supported", protocol)
}
Expand Down
Loading