diff --git a/server/gitea/client.go b/server/gitea/client.go index 49983dd..85e9879 100644 --- a/server/gitea/client.go +++ b/server/gitea/client.go @@ -27,6 +27,8 @@ type FileResponse struct { Body []byte } +func joinURL(giteaRoot string, paths ...string) string { return giteaRoot + path.Join(paths...) } + func (f FileResponse) IsEmpty() bool { return len(f.Body) != 0 } func NewClient(giteaRoot, giteaAPIToken string) *Client { @@ -42,7 +44,7 @@ func NewClient(giteaRoot, giteaAPIToken string) *Client { func (client *Client) GiteaRawContent(targetOwner, targetRepo, ref, resource string) ([]byte, error) { req := fasthttp.AcquireRequest() - req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref))) + req.SetRequestURI(joinURL(client.giteaRoot, giteaAPIRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref))) req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken) res := fasthttp.AcquireResponse() @@ -63,7 +65,7 @@ func (client *Client) ServeRawContent(uri string) (*fasthttp.Response, error) { fastClient := getFastHTTPClient(10 * time.Second) req := fasthttp.AcquireRequest() - req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, uri)) + req.SetRequestURI(joinURL(client.giteaRoot, giteaAPIRepos, uri)) req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken) resp := fasthttp.AcquireResponse() @@ -87,7 +89,7 @@ func (client *Client) GiteaGetRepoBranchTimestamp(repoOwner, repoName, branchNam fastClient := getFastHTTPClient(5 * time.Second) req := fasthttp.AcquireRequest() - req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, repoOwner, repoName, "branches", branchName)) + req.SetRequestURI(joinURL(client.giteaRoot, giteaAPIRepos, repoOwner, repoName, "branches", branchName)) req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken) res := fasthttp.AcquireResponse() @@ -104,7 +106,7 @@ func (client *Client) GiteaGetRepoDefaultBranch(repoOwner, repoName string) (str fastClient := getFastHTTPClient(5 * time.Second) req := fasthttp.AcquireRequest() - req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, repoOwner, repoName)) + req.SetRequestURI(joinURL(client.giteaRoot, giteaAPIRepos, repoOwner, repoName)) req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken) res := fasthttp.AcquireResponse()