chore: refine config error messages and adjust internal config structures

This commit is contained in:
ExplodingDragon
2026-01-31 23:50:32 +08:00
parent 662370e018
commit b580741a4e
7 changed files with 72 additions and 40 deletions

View File

@@ -75,7 +75,7 @@ func main() {
provider, domain, memory,
pkg.WithClient(http.DefaultClient),
pkg.WithEvent(subscriber),
pkg.WithMetaCache(memory, 0, 0),
pkg.WithMetaCache(memory, 0, 0, 0),
pkg.WithBlobCache(&nopCache{}, 0),
pkg.WithErrorHandler(func(w http.ResponseWriter, r *http.Request, err error) {
if errors.Is(err, os.ErrNotExist) {

View File

@@ -84,14 +84,16 @@ type ConfigEvent struct {
}
type ConfigCache struct {
Meta string `yaml:"meta"` // 元数据缓存
MetaTTL time.Duration `yaml:"meta_ttl"` // 缓存时间
MetaRefresh time.Duration `yaml:"meta_refresh"` // 刷新时间
Meta string `yaml:"meta"` // 元数据缓存
MetaTTL time.Duration `yaml:"meta_ttl"` // 缓存时间
MetaRefresh time.Duration `yaml:"meta_refresh"` // 刷新时间
MetaRefreshConcurrent int `yaml:"meta_refresh_concurrent"` // 并发刷新限制
Blob string `yaml:"blob"` // 缓存归档位置
BlobTTL time.Duration `yaml:"blob_ttl"` // 缓存归档位置
BlobLimit units.Base2Bytes `yaml:"blob_limit"` // 单个文件最大大小
BlobConcurrent uint64 `yaml:"blob_concurrent"` // 并发缓存限制
BlobNotFoundTTL time.Duration `yaml:"blob_not_found_ttl"` // 404 缓存时间
BackendConcurrent uint64 `yaml:"backend_concurrent"` // 并发后端请求限制
}
@@ -108,11 +110,8 @@ func LoadConfig(path string) (*Config, error) {
return nil, err
}
if c.Domain == "" {
return nil, errors.New("domain is required")
}
if c.Database.URL == "" {
return nil, errors.New("c is required")
return nil, errors.New("database.url is required")
}
if c.Event.URL == "" {
c.Event.URL = "memory://"

View File

@@ -56,6 +56,7 @@ func main() {
uint64(config.Cache.BlobLimit),
config.Cache.BlobConcurrent,
config.Cache.BackendConcurrent,
config.Cache.BlobNotFoundTTL,
)
defer backend.Close()
db, err := kv.NewKVFromURL(config.Database.URL)
@@ -77,7 +78,7 @@ func main() {
db,
pkg.WithClient(http.DefaultClient),
pkg.WithEvent(event),
pkg.WithMetaCache(cacheMeta, config.Cache.MetaTTL, config.Cache.MetaRefresh),
pkg.WithMetaCache(cacheMeta, config.Cache.MetaTTL, config.Cache.MetaRefresh, config.Cache.MetaRefreshConcurrent),
pkg.WithBlobCache(cacheBlob.Child("filter"), config.Cache.BlobTTL),
pkg.WithErrorHandler(config.ErrorHandler),
pkg.WithFilterConfig(config.Filters),