Define path prefixes in a package that doesn't create import cycles

This commit is contained in:
Neil Alexander 2020-05-22 14:18:41 +01:00
parent 06d5f1e6dc
commit 3c3e014901
4 changed files with 23 additions and 9 deletions

View file

@ -6,7 +6,10 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
"github.com/matrix-org/dendrite/internal/httpapis"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
)
@ -21,6 +24,14 @@ func PostJSON(
return err
}
parsedAPIURL, err := url.Parse(apiURL)
if err != nil {
return err
}
parsedAPIURL.Path = httpapis.InternalPathPrefix + strings.TrimLeft(parsedAPIURL.Path, "/")
apiURL = parsedAPIURL.String()
req, err := http.NewRequest(http.MethodPost, apiURL, bytes.NewReader(jsonBytes))
if err != nil {
return err