chore: Format

This commit is contained in:
PapaTutuWawa 2024-01-01 00:38:39 +01:00
parent 1154eff9ae
commit 85bd71cff3
7 changed files with 97 additions and 100 deletions

View File

@ -5,8 +5,8 @@ import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"encoding/json"
"encoding/base64"
"encoding/json"
"io/ioutil"
"github.com/go-acme/lego/v4/acme"
@ -61,7 +61,6 @@ func ClientFromFile(storage, acmeServer string) (*lego.Client, error) {
contacts = append(contacts, v.(string))
}
registration := registration.Resource{
URI: reg["uri"].(string),
Body: acme.Account{

View File

@ -74,7 +74,7 @@ type CertificateWrapper struct {
func (c *CertificateWrapper) GetPrivateKey() *rsa.PrivateKey {
data, _ := base64.StdEncoding.DecodeString(c.PrivateKeyEncoded)
pk, _ := certcrypto.ParsePEMPrivateKey(data);
pk, _ := certcrypto.ParsePEMPrivateKey(data)
return pk.(*rsa.PrivateKey)
}
@ -160,7 +160,7 @@ func fallbackCert(pagesDomain string) (*CertificateWrapper, error) {
return nil, err
}
notAfter := time.Now().Add(time.Hour*24*7);
notAfter := time.Now().Add(time.Hour * 24 * 7)
cert := x509.Certificate{
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
@ -222,7 +222,7 @@ func isCertStillValid(cert CertificateWrapper) bool {
func makeTlsConfig(pagesDomain, path string, acmeClient *lego.Client) *tls.Config {
return &tls.Config{
InsecureSkipVerify: true,
GetCertificate: func (info *tls.ClientHelloInfo) (*tls.Certificate, error) {
GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
// Validate that we should even care about this domain
if !strings.HasSuffix(info.ServerName, pagesDomain) {
// Note: We do not check err here because err != nil

4
dns.go
View File

@ -14,8 +14,8 @@ const (
)
var (
cnameCache = cache.New(1 * time.Hour, 1 * time.Hour)
txtRepoCache = cache.New(1 * time.Hour, 1 * time.Hour)
cnameCache = cache.New(1*time.Hour, 1*time.Hour)
txtRepoCache = cache.New(1*time.Hour, 1*time.Hour)
)
func lookupRepoTXT(domain string) (string, error) {

View File

@ -2,18 +2,18 @@ package main
import (
"crypto/tls"
"os"
"errors"
"fmt"
"net"
"net/http"
"os"
"strings"
"time"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/go-acme/lego/v4/challenge/http01"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
const (
@ -35,7 +35,6 @@ func handleSubdomain(domain string, cname string, path, giteaUrl string, giteaCl
cname,
path,
giteaClient,
)
if err != nil {
log.Errorf("Failed to get repo: %s", err)
@ -50,7 +49,7 @@ func Handler(pagesDomain, giteaUrl string, giteaClient *gitea.Client) http.Handl
return func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Server", "rio")
if strings.HasSuffix(req.Host, pagesDomain){
if strings.HasSuffix(req.Host, pagesDomain) {
if handleLetsEncryptChallenge(w, req) {
return
}

View File

@ -13,7 +13,7 @@ import (
)
var (
pageCache = cache.New(6 * time.Hour, 1 * time.Hour)
pageCache = cache.New(6*time.Hour, 1*time.Hour)
)
type PageContentCache struct {
@ -98,7 +98,7 @@ func serveFile(username, reponame, path, giteaUrl string, w http.ResponseWriter)
}
pathParts := strings.Split(path, ".")
ext := pathParts[len(pathParts) - 1]
ext := pathParts[len(pathParts)-1]
mimeType = mime.TypeByExtension("." + ext)
now := time.Now()

15
repo.go
View File

@ -11,10 +11,9 @@ import (
)
var (
pathCache = cache.New(1 * time.Hour, 1 * time.Hour)
pathCache = cache.New(1*time.Hour, 1*time.Hour)
)
type PageCacheEntry struct {
Repository *gitea.Repository
Path string
@ -24,10 +23,10 @@ func makePageCacheKey(domain, path string) string {
return domain + "/" + path
}
/// Try to find the repository with name @reponame of the user @username. If @cname
/// is not "", then it also verifies that the repository contains a "CNAME" with
/// the value of @cname as its content. @host, @domain, and @path are passed for
/// caching on success.
// / Try to find the repository with name @reponame of the user @username. If @cname
// / is not "", then it also verifies that the repository contains a "CNAME" with
// / the value of @cname as its content. @host, @domain, and @path are passed for
// / caching on success.
func lookupRepositoryAndCache(username, reponame, host, domain, path, cname string, giteaClient *gitea.Client) (*gitea.Repository, error) {
log.Debugf("Looking up repository %s/%s", username, reponame)
repo, _, err := giteaClient.GetRepo(username, reponame)
@ -113,9 +112,9 @@ func RepoFromPath(username, host, cname, path string, giteaClient *gitea.Client)
repoLookup,
)
reponame = repoLookup
} else if (cname != "") {
} else if cname != "" {
// Allow naming the repository "example.org" (But give the TXT record preference)
reponame = cname;
reponame = cname
}
log.Debugf("Trying repository %s/%s", username, reponame)