清理代码

This commit is contained in:
dragon
2025-09-25 11:57:23 +08:00
parent 9a425a057e
commit 92c0f73020
13 changed files with 92 additions and 74 deletions

View File

@@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"
"gopkg.d7z.net/gitea-pages/pkg/utils"
"gopkg.d7z.net/gitea-pages/pkg/middleware/config"
)
type Alias struct {
@@ -15,10 +15,10 @@ type Alias struct {
}
type DomainAlias struct {
config utils.KVConfig
config config.KVConfig
}
func NewDomainAlias(config utils.KVConfig) *DomainAlias {
func NewDomainAlias(config config.KVConfig) *DomainAlias {
return &DomainAlias{config: config}
}
@@ -55,9 +55,9 @@ func (a *DomainAlias) Bind(ctx context.Context, domains []string, owner, repo, b
}
aliasMetaRaw, _ := json.Marshal(aliasMeta)
domainsRaw, _ := json.Marshal(domains)
_ = a.config.Put(ctx, rKey, string(domainsRaw), utils.TtlKeep)
_ = a.config.Put(ctx, rKey, string(domainsRaw), config.TtlKeep)
for _, domain := range domains {
if err := a.config.Put(ctx, "domain/alias/"+domain, string(aliasMetaRaw), utils.TtlKeep); err != nil {
if err := a.config.Put(ctx, "domain/alias/"+domain, string(aliasMetaRaw), config.TtlKeep); err != nil {
return err
}
}

View File

@@ -14,6 +14,8 @@ import (
"github.com/pkg/errors"
"go.uber.org/zap"
"gopkg.d7z.net/gitea-pages/pkg/middleware/cache"
"gopkg.d7z.net/gitea-pages/pkg/middleware/config"
"gopkg.d7z.net/gitea-pages/pkg/utils"
)
@@ -35,7 +37,7 @@ type Backend interface {
type CacheBackend struct {
backend Backend
config utils.KVConfig
config config.KVConfig
ttl time.Duration
}
@@ -43,7 +45,7 @@ func (c *CacheBackend) Close() error {
return c.backend.Close()
}
func NewCacheBackend(backend Backend, config utils.KVConfig, ttl time.Duration) *CacheBackend {
func NewCacheBackend(backend Backend, config config.KVConfig, ttl time.Duration) *CacheBackend {
return &CacheBackend{backend: backend, config: config, ttl: ttl}
}
@@ -113,12 +115,12 @@ func (c *CacheBackend) Open(ctx context.Context, client *http.Client, owner, rep
type CacheBackendBlobReader struct {
client *http.Client
cache utils.Cache
cache cache.Cache
base Backend
maxSize int
}
func NewCacheBackendBlobReader(client *http.Client, base Backend, cache utils.Cache, maxCacheSize int) *CacheBackendBlobReader {
func NewCacheBackendBlobReader(client *http.Client, base Backend, cache cache.Cache, maxCacheSize int) *CacheBackendBlobReader {
return &CacheBackendBlobReader{client: client, base: base, cache: cache, maxSize: maxCacheSize}
}
@@ -173,7 +175,7 @@ func (c *CacheBackendBlobReader) Open(ctx context.Context, owner, repo, commit,
if err = c.cache.Put(key, bytes.NewBuffer(allBytes)); err != nil {
zap.L().Warn("缓存归档失败", zap.Error(err), zap.Int("Size", len(allBytes)), zap.Int("MaxSize", c.maxSize))
}
return &utils.CacheContent{
return &cache.CacheContent{
ReadSeekCloser: utils.NopCloser{
ReadSeeker: bytes.NewReader(allBytes),
},

View File

@@ -6,8 +6,7 @@ import (
"strings"
"github.com/pkg/errors"
"gopkg.d7z.net/gitea-pages/pkg/utils"
"gopkg.d7z.net/gitea-pages/pkg/middleware/config"
"go.uber.org/zap"
)
@@ -20,7 +19,7 @@ type PageDomain struct {
defaultBranch string
}
func NewPageDomain(meta *ServerMeta, config utils.KVConfig, baseDomain, defaultBranch string) *PageDomain {
func NewPageDomain(meta *ServerMeta, config config.KVConfig, baseDomain, defaultBranch string) *PageDomain {
return &PageDomain{
baseDomain: baseDomain,
defaultBranch: defaultBranch,

View File

@@ -13,6 +13,7 @@ import (
"time"
"go.uber.org/zap"
"gopkg.d7z.net/gitea-pages/pkg/middleware/config"
"gopkg.in/yaml.v3"
"github.com/gobwas/glob"
@@ -30,13 +31,13 @@ type ServerMeta struct {
Domain string
client *http.Client
cache utils.KVConfig
cache config.KVConfig
ttl time.Duration
locker *utils.Locker
}
func NewServerMeta(client *http.Client, backend Backend, kv utils.KVConfig, domain string, ttl time.Duration) *ServerMeta {
func NewServerMeta(client *http.Client, backend Backend, kv config.KVConfig, domain string, ttl time.Duration) *ServerMeta {
return &ServerMeta{backend, domain, client, kv, ttl, utils.NewLocker()}
}