From 6af6523a0f83a171e19b5bb9c2b25b28d4916bee Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 9 Dec 2021 20:16:43 +0100 Subject: [PATCH] code format --- server/try.go | 2 +- server/upstream/domains.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/try.go b/server/try.go index 6dffa44..31cd7f4 100644 --- a/server/try.go +++ b/server/try.go @@ -29,7 +29,7 @@ func tryUpstream(ctx *fasthttp.RequestCtx, if targetRepo != "pages" { path := strings.SplitN(canonicalPath, "/", 3) if len(path) >= 3 { - canonicalPath = "/" + strings.SplitN(canonicalPath, "/", 3)[2] + canonicalPath = "/" + path[2] } } ctx.Redirect("https://"+canonicalDomain+canonicalPath, fasthttp.StatusTemporaryRedirect) diff --git a/server/upstream/domains.go b/server/upstream/domains.go index 5971e13..47a5564 100644 --- a/server/upstream/domains.go +++ b/server/upstream/domains.go @@ -8,9 +8,10 @@ import ( "codeberg.org/codeberg/pages/server/cache" ) -// CheckCanonicalDomain returns the canonical domain specified in the repo (using the file `.canonical-domain`). -func CheckCanonicalDomain(targetOwner, targetRepo, targetBranch, actualDomain, mainDomainSuffix, giteaRoot, giteaApiToken string, canonicalDomainCache cache.SetGetKey) (canonicalDomain string, valid bool) { +// CheckCanonicalDomain returns the canonical domain specified in the repo (using the `.domains` file). +func CheckCanonicalDomain(targetOwner, targetRepo, targetBranch, actualDomain, mainDomainSuffix, giteaRoot, giteaAPIToken string, canonicalDomainCache cache.SetGetKey) (string, bool) { domains := []string{} + valid := false if cachedValue, ok := canonicalDomainCache.Get(targetOwner + "/" + targetRepo + "/" + targetBranch); ok { domains = cachedValue.([]string) for _, domain := range domains { @@ -21,7 +22,7 @@ func CheckCanonicalDomain(targetOwner, targetRepo, targetBranch, actualDomain, m } } else { req := fasthttp.AcquireRequest() - req.SetRequestURI(giteaRoot + "/api/v1/repos/" + targetOwner + "/" + targetRepo + "/raw/" + targetBranch + "/.domains" + "?access_token=" + giteaApiToken) + req.SetRequestURI(giteaRoot + "/api/v1/repos/" + targetOwner + "/" + targetRepo + "/raw/" + targetBranch + "/.domains" + "?access_token=" + giteaAPIToken) res := fasthttp.AcquireResponse() err := client.Do(req, res) @@ -48,6 +49,5 @@ func CheckCanonicalDomain(targetOwner, targetRepo, targetBranch, actualDomain, m } _ = canonicalDomainCache.Set(targetOwner+"/"+targetRepo+"/"+targetBranch, domains, canonicalDomainCacheTimeout) } - canonicalDomain = domains[0] - return + return domains[0], valid }