mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 22:06:57 +00:00
Add golangci linters
- Remove unnecessary type conversion. - Fix gocritic checks.
This commit is contained in:
parent
df5199c9a3
commit
827c582147
7 changed files with 40 additions and 21 deletions
20
.golangci.yml
Normal file
20
.golangci.yml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
linters-settings:
|
||||||
|
gocritic:
|
||||||
|
enabled-tags:
|
||||||
|
- diagnostic
|
||||||
|
- experimental
|
||||||
|
- opinionated
|
||||||
|
- performance
|
||||||
|
- style
|
||||||
|
disabled-checks:
|
||||||
|
- importShadow
|
||||||
|
- ifElseChain
|
||||||
|
- hugeParam
|
||||||
|
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
- unconvert
|
||||||
|
- gocritic
|
||||||
|
|
||||||
|
run:
|
||||||
|
timeout: 5m
|
|
@ -65,7 +65,7 @@ func Serve(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
allowedCorsDomains := AllowedCorsDomains
|
allowedCorsDomains := AllowedCorsDomains
|
||||||
if len(rawDomain) != 0 {
|
if rawDomain != "" {
|
||||||
allowedCorsDomains = append(allowedCorsDomains, rawDomain)
|
allowedCorsDomains = append(allowedCorsDomains, rawDomain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,10 @@ func TLSConfig(mainDomainSuffix string,
|
||||||
|
|
||||||
if info.SupportedProtos != nil {
|
if info.SupportedProtos != nil {
|
||||||
for _, proto := range info.SupportedProtos {
|
for _, proto := range info.SupportedProtos {
|
||||||
if proto == tlsalpn01.ACMETLS1Protocol {
|
if proto != tlsalpn01.ACMETLS1Protocol {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
challenge, ok := challengeCache.Get(sni)
|
challenge, ok := challengeCache.Get(sni)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("no challenge for this domain")
|
return nil, errors.New("no challenge for this domain")
|
||||||
|
@ -65,7 +68,6 @@ func TLSConfig(mainDomainSuffix string,
|
||||||
return cert, nil
|
return cert, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
targetOwner := ""
|
targetOwner := ""
|
||||||
if strings.HasSuffix(sni, mainDomainSuffix) || strings.EqualFold(sni, mainDomainSuffix[1:]) {
|
if strings.HasSuffix(sni, mainDomainSuffix) || strings.EqualFold(sni, mainDomainSuffix[1:]) {
|
||||||
|
@ -216,7 +218,7 @@ func retrieveCertFromDB(sni, mainDomainSuffix, dnsProvider string, acmeUseRateLi
|
||||||
}
|
}
|
||||||
|
|
||||||
// renew certificates 7 days before they expire
|
// renew certificates 7 days before they expire
|
||||||
if !tlsCertificate.Leaf.NotAfter.After(time.Now().Add(7 * 24 * time.Hour)) {
|
if tlsCertificate.Leaf.NotAfter.Before(time.Now().Add(7 * 24 * time.Hour)) {
|
||||||
// TODO: add ValidUntil to custom res struct
|
// TODO: add ValidUntil to custom res struct
|
||||||
if res.CSR != nil && len(res.CSR) > 0 {
|
if res.CSR != nil && len(res.CSR) > 0 {
|
||||||
// CSR stores the time when the renewal shall be tried again
|
// CSR stores the time when the renewal shall be tried again
|
||||||
|
@ -479,7 +481,7 @@ func MaintainCertDB(ctx context.Context, interval time.Duration, mainDomainSuffi
|
||||||
}
|
}
|
||||||
|
|
||||||
tlsCertificates, err := certcrypto.ParsePEMBundle(res.Certificate)
|
tlsCertificates, err := certcrypto.ParsePEMBundle(res.Certificate)
|
||||||
if err != nil || !tlsCertificates[0].NotAfter.After(now) {
|
if err != nil || tlsCertificates[0].NotAfter.Before(now) {
|
||||||
err := certDB.Delete(string(key))
|
err := certDB.Delete(string(key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("Deleting expired certificate for %q failed", string(key))
|
log.Error().Err(err).Msgf("Deleting expired certificate for %q failed", string(key))
|
||||||
|
@ -510,7 +512,7 @@ func MaintainCertDB(ctx context.Context, interval time.Duration, mainDomainSuffi
|
||||||
tlsCertificates, err := certcrypto.ParsePEMBundle(res.Certificate)
|
tlsCertificates, err := certcrypto.ParsePEMBundle(res.Certificate)
|
||||||
|
|
||||||
// renew main certificate 30 days before it expires
|
// renew main certificate 30 days before it expires
|
||||||
if !tlsCertificates[0].NotAfter.After(time.Now().Add(30 * 24 * time.Hour)) {
|
if tlsCertificates[0].NotAfter.Before(time.Now().Add(30 * 24 * time.Hour)) {
|
||||||
go (func() {
|
go (func() {
|
||||||
_, err = obtainCert(mainDomainAcmeClient, []string{"*" + mainDomainSuffix, mainDomainSuffix[1:]}, res, "", dnsProvider, mainDomainSuffix, acmeUseRateLimits, certDB)
|
_, err = obtainCert(mainDomainAcmeClient, []string{"*" + mainDomainSuffix, mainDomainSuffix[1:]}, res, "", dnsProvider, mainDomainSuffix, acmeUseRateLimits, certDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -44,7 +44,7 @@ func (p aDB) Get(name string) (*certificate.Resource, error) {
|
||||||
if resBytes == nil {
|
if resBytes == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if err = gob.NewDecoder(bytes.NewBuffer(resBytes)).Decode(cert); err != nil {
|
if err := gob.NewDecoder(bytes.NewBuffer(resBytes)).Decode(cert); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return cert, nil
|
return cert, nil
|
||||||
|
|
|
@ -42,10 +42,7 @@ func (f FileResponse) IsEmpty() bool {
|
||||||
return len(f.Body) != 0
|
return len(f.Body) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f FileResponse) createHttpResponse(cacheKey string) (http.Header, int) {
|
func (f FileResponse) createHttpResponse(cacheKey string) (header http.Header, statusCode int) {
|
||||||
header := make(http.Header)
|
|
||||||
var statusCode int
|
|
||||||
|
|
||||||
if f.Exists {
|
if f.Exists {
|
||||||
statusCode = http.StatusOK
|
statusCode = http.StatusOK
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
func (o *Options) GetBranchTimestamp(giteaClient *gitea.Client) (bool, error) {
|
func (o *Options) GetBranchTimestamp(giteaClient *gitea.Client) (bool, error) {
|
||||||
log := log.With().Strs("BranchInfo", []string{o.TargetOwner, o.TargetRepo, o.TargetBranch}).Logger()
|
log := log.With().Strs("BranchInfo", []string{o.TargetOwner, o.TargetRepo, o.TargetBranch}).Logger()
|
||||||
|
|
||||||
if len(o.TargetBranch) == 0 {
|
if o.TargetBranch == "" {
|
||||||
// Get default branch
|
// Get default branch
|
||||||
defaultBranch, err := giteaClient.GiteaGetRepoDefaultBranch(o.TargetOwner, o.TargetRepo)
|
defaultBranch, err := giteaClient.GiteaGetRepoDefaultBranch(o.TargetOwner, o.TargetRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -83,7 +83,7 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client) (fin
|
||||||
// Check if the browser has a cached version
|
// Check if the browser has a cached version
|
||||||
if ctx.Response() != nil {
|
if ctx.Response() != nil {
|
||||||
if ifModifiedSince, err := time.Parse(time.RFC1123, ctx.Response().Header.Get(headerIfModifiedSince)); err == nil {
|
if ifModifiedSince, err := time.Parse(time.RFC1123, ctx.Response().Header.Get(headerIfModifiedSince)); err == nil {
|
||||||
if !ifModifiedSince.Before(o.BranchTimestamp) {
|
if ifModifiedSince.After(o.BranchTimestamp) {
|
||||||
ctx.RespWriter.WriteHeader(http.StatusNotModified)
|
ctx.RespWriter.WriteHeader(http.StatusNotModified)
|
||||||
log.Trace().Msg("check response against last modified: valid")
|
log.Trace().Msg("check response against last modified: valid")
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue