Skip to content

Commit

Permalink
backport url.JoinPath for go1.18
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser committed Sep 22, 2022
1 parent 6c66409 commit 7a8e1b8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions services/notifications/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"
"os"
"os/signal"
"path"
"syscall"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
Expand Down Expand Up @@ -155,7 +156,7 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) {
return
}

shareLink, err := url.JoinPath(e.Executant.Idp, "files/spaces/projects", storagespace.FormatResourceID(*e.ID))
shareLink, err := urlJoinPath(e.Executant.Idp, "files/spaces/projects", storagespace.FormatResourceID(*e.ID))

if err != nil {
s.logger.Error().
Expand Down Expand Up @@ -268,7 +269,7 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) {
return
}

shareLink, err := url.JoinPath(e.Executant.Idp, "files/shares/with-me")
shareLink, err := urlJoinPath(e.Executant.Idp, "files/shares/with-me")

if err != nil {
s.logger.Error().
Expand Down Expand Up @@ -306,3 +307,13 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) {
Msg("failed to send a message")
}
}

// TODO: this function is a backport for go1.19 url.JoinPath, upon go bump, replace this
func urlJoinPath(base string, elements ...string) (string, error) {
u, err := url.Parse(base)
if err != nil {
return "", err
}
u.Path = path.Join(append([]string{u.Path}, elements...)...)
return u.String(), nil
}

0 comments on commit 7a8e1b8

Please sign in to comment.