Skip to content

Commit c00f77b

Browse files
authored
refactor: better combineBaseURLAndPath (#173)
On-behalf-of: @SAP [email protected] Signed-off-by: Artem Shcherbatiuk <[email protected]>
1 parent ee018ba commit c00f77b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

listener/kcp/workspace_config.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package kcp
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
kcptenancy "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1"
87
"github.com/openmfp/golang-commons/logger"
98
"net/url"
@@ -55,7 +54,7 @@ func virtualWorkspaceConfigFromCfg(
5554
return nil, errors.Join(ErrFailedToGetAPIExport, err)
5655
}
5756

58-
log.Warn().Msg(fmt.Sprintf("failed to find %s ApiExport, listener will not watch ApiBinding changes in realtime", appCfg.ApiExportName))
57+
log.Warn().Str("apiexport", appCfg.ApiExportName).Msg("failed to find ApiExport, listener will not watch ApiBinding changes in realtime")
5958
}
6059

6160
if len(apiExport.Status.VirtualWorkspaces) == 0 { // nolint: staticcheck
@@ -88,11 +87,21 @@ func combineBaseURLAndPath(baseURLStr, pathURLStr string) (string, error) {
8887
return "", errors.Join(ErrInvalidURL, err)
8988
}
9089

90+
if pathURLStr == "" {
91+
return baseURL.String() + "/", nil
92+
}
93+
9194
path := pathURL.Path
9295

9396
if !strings.HasPrefix(path, "/") {
9497
path = "/" + path
9598
}
9699

97-
return baseURL.ResolveReference(&url.URL{Path: path}).String(), nil
100+
finalURL := url.URL{
101+
Scheme: baseURL.Scheme,
102+
Host: baseURL.Host,
103+
Path: path,
104+
}
105+
106+
return finalURL.String(), nil
98107
}

0 commit comments

Comments
 (0)