From 77e39b22132696cadb29b894a8a19ec8494d139d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 5 Dec 2021 16:24:26 +0100 Subject: [PATCH] unexport if posible --- server/certificates/certificates.go | 4 ++-- server/dns/const.go | 4 ++-- server/dns/dns.go | 2 +- server/upstream/const.go | 22 +++++++++++----------- server/upstream/domains.go | 2 +- server/upstream/helper.go | 4 ++-- server/upstream/upstream.go | 10 +++++----- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/server/certificates/certificates.go b/server/certificates/certificates.go index afaa4f0..fb61bd8 100644 --- a/server/certificates/certificates.go +++ b/server/certificates/certificates.go @@ -134,7 +134,7 @@ func TLSConfig(mainDomainSuffix []byte, } } -func CheckUserLimit(user string) error { +func checkUserLimit(user string) error { userLimit, ok := acmeClientCertificateLimitPerUser[user] if !ok { // Each Codeberg user can only add 10 new domains per day. @@ -292,7 +292,7 @@ func obtainCert(acmeClient *lego.Client, domains []string, renew *certificate.Re } if res == nil { if user != "" { - if err := CheckUserLimit(user); err != nil { + if err := checkUserLimit(user); err != nil { return tls.Certificate{}, err } } diff --git a/server/dns/const.go b/server/dns/const.go index fcf669b..bb2413b 100644 --- a/server/dns/const.go +++ b/server/dns/const.go @@ -2,5 +2,5 @@ package dns import "time" -// DnsLookupCacheTimeout specifies the timeout for the DNS lookup cache. -var DnsLookupCacheTimeout = 15 * time.Minute +// lookupCacheTimeout specifies the timeout for the DNS lookup cache. +var lookupCacheTimeout = 15 * time.Minute diff --git a/server/dns/dns.go b/server/dns/dns.go index c231439..dc759b0 100644 --- a/server/dns/dns.go +++ b/server/dns/dns.go @@ -32,7 +32,7 @@ func GetTargetFromDNS(domain, mainDomainSuffix string, dnsLookupCache cache.SetG } } } - _ = dnsLookupCache.Set(domain, cname, DnsLookupCacheTimeout) + _ = dnsLookupCache.Set(domain, cname, lookupCacheTimeout) } if cname == "" { return diff --git a/server/upstream/const.go b/server/upstream/const.go index 8c351df..77f64dd 100644 --- a/server/upstream/const.go +++ b/server/upstream/const.go @@ -2,20 +2,20 @@ package upstream import "time" -// DefaultBranchCacheTimeout specifies the timeout for the default branch cache. It can be quite long. -var DefaultBranchCacheTimeout = 15 * time.Minute +// defaultBranchCacheTimeout specifies the timeout for the default branch cache. It can be quite long. +var defaultBranchCacheTimeout = 15 * time.Minute -// BranchExistanceCacheTimeout specifies the timeout for the branch timestamp & existance cache. It should be shorter -// than FileCacheTimeout, as that gets invalidated if the branch timestamp has changed. That way, repo changes will be +// branchExistenceCacheTimeout specifies the timeout for the branch timestamp & existence cache. It should be shorter +// than fileCacheTimeout, as that gets invalidated if the branch timestamp has changed. That way, repo changes will be // picked up faster, while still allowing the content to be cached longer if nothing changes. -var BranchExistanceCacheTimeout = 5 * time.Minute +var branchExistenceCacheTimeout = 5 * time.Minute -// FileCacheTimeout specifies the timeout for the file content cache - you might want to make this quite long, depending +// fileCacheTimeout specifies the timeout for the file content cache - you might want to make this quite long, depending // on your available memory. -var FileCacheTimeout = 5 * time.Minute +var fileCacheTimeout = 5 * time.Minute -// FileCacheSizeLimit limits the maximum file size that will be cached, and is set to 1 MB by default. -var FileCacheSizeLimit = 1024 * 1024 +// fileCacheSizeLimit limits the maximum file size that will be cached, and is set to 1 MB by default. +var fileCacheSizeLimit = 1024 * 1024 -// CanonicalDomainCacheTimeout specifies the timeout for the canonical domain cache. -var CanonicalDomainCacheTimeout = 15 * time.Minute +// canonicalDomainCacheTimeout specifies the timeout for the canonical domain cache. +var canonicalDomainCacheTimeout = 15 * time.Minute diff --git a/server/upstream/domains.go b/server/upstream/domains.go index 89bc7fb..5971e13 100644 --- a/server/upstream/domains.go +++ b/server/upstream/domains.go @@ -46,7 +46,7 @@ func CheckCanonicalDomain(targetOwner, targetRepo, targetBranch, actualDomain, m if targetRepo != "" && targetRepo != "pages" { domains[len(domains)-1] += "/" + targetRepo } - _ = canonicalDomainCache.Set(targetOwner+"/"+targetRepo+"/"+targetBranch, domains, CanonicalDomainCacheTimeout) + _ = canonicalDomainCache.Set(targetOwner+"/"+targetRepo+"/"+targetBranch, domains, canonicalDomainCacheTimeout) } canonicalDomain = domains[0] return diff --git a/server/upstream/helper.go b/server/upstream/helper.go index d8882b6..b5ee77a 100644 --- a/server/upstream/helper.go +++ b/server/upstream/helper.go @@ -31,7 +31,7 @@ func GetBranchTimestamp(owner, repo, branch, giteaRoot, giteaApiToken string, br // TODO: use header for API key? status, body, err := fasthttp.GetTimeout(body, giteaRoot+"/api/v1/repos/"+owner+"/"+repo+"?access_token="+giteaApiToken, 5*time.Second) if err != nil || status != 200 { - _ = branchTimestampCache.Set(owner+"/"+repo+"/"+branch, nil, DefaultBranchCacheTimeout) + _ = branchTimestampCache.Set(owner+"/"+repo+"/"+branch, nil, defaultBranchCacheTimeout) return nil } result.Branch = fastjson.GetString(body, "default_branch") @@ -44,7 +44,7 @@ func GetBranchTimestamp(owner, repo, branch, giteaRoot, giteaApiToken string, br } result.Timestamp, _ = time.Parse(time.RFC3339, fastjson.GetString(body, "commit", "timestamp")) - _ = branchTimestampCache.Set(owner+"/"+repo+"/"+branch, result, BranchExistanceCacheTimeout) + _ = branchTimestampCache.Set(owner+"/"+repo+"/"+branch, result, branchExistenceCacheTimeout) return result } diff --git a/server/upstream/upstream.go b/server/upstream/upstream.go index 396f3c5..306e1db 100644 --- a/server/upstream/upstream.go +++ b/server/upstream/upstream.go @@ -101,7 +101,7 @@ func (options *Options) Upstream(ctx *fasthttp.RequestCtx, targetOwner, targetRe if optionsForIndexPages.Upstream(ctx, targetOwner, targetRepo, targetBranch, strings.TrimSuffix(targetPath, "/")+"/"+indexPage, giteaRoot, giteaApiToken, branchTimestampCache, fileResponseCache) { _ = fileResponseCache.Set(uri+"?timestamp="+strconv.FormatInt(options.BranchTimestamp.Unix(), 10), fileResponse{ exists: false, - }, FileCacheTimeout) + }, fileCacheTimeout) return true } } @@ -111,7 +111,7 @@ func (options *Options) Upstream(ctx *fasthttp.RequestCtx, targetOwner, targetRe if optionsForIndexPages.Upstream(ctx, targetOwner, targetRepo, targetBranch, targetPath+".html", giteaRoot, giteaApiToken, branchTimestampCache, fileResponseCache) { _ = fileResponseCache.Set(uri+"?timestamp="+strconv.FormatInt(options.BranchTimestamp.Unix(), 10), fileResponse{ exists: false, - }, FileCacheTimeout) + }, fileCacheTimeout) return true } } @@ -120,7 +120,7 @@ func (options *Options) Upstream(ctx *fasthttp.RequestCtx, targetOwner, targetRe // Update cache if the request is fresh _ = fileResponseCache.Set(uri+"?timestamp="+strconv.FormatInt(options.BranchTimestamp.Unix(), 10), fileResponse{ exists: false, - }, FileCacheTimeout) + }, fileCacheTimeout) } return false } @@ -167,7 +167,7 @@ func (options *Options) Upstream(ctx *fasthttp.RequestCtx, targetOwner, targetRe // Write the response body to the original request var cacheBodyWriter bytes.Buffer if res != nil { - if res.Header.ContentLength() > FileCacheSizeLimit { + if res.Header.ContentLength() > fileCacheSizeLimit { err = res.BodyWriteTo(ctx.Response.BodyWriter()) } else { // TODO: cache is half-empty if request is cancelled - does the ctx.Err() below do the trick? @@ -187,7 +187,7 @@ func (options *Options) Upstream(ctx *fasthttp.RequestCtx, targetOwner, targetRe cachedResponse.exists = true cachedResponse.mimeType = mimeType cachedResponse.body = cacheBodyWriter.Bytes() - _ = fileResponseCache.Set(uri+"?timestamp="+strconv.FormatInt(options.BranchTimestamp.Unix(), 10), cachedResponse, FileCacheTimeout) + _ = fileResponseCache.Set(uri+"?timestamp="+strconv.FormatInt(options.BranchTimestamp.Unix(), 10), cachedResponse, fileCacheTimeout) } return true