修复部分语法问题
This commit is contained in:
11
config.go
11
config.go
@@ -96,12 +96,16 @@ func (c *Config) NewPageServerOptions() (*pkg.ServerOptions, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to init cache meta")
|
return nil, errors.Wrapf(err, "failed to init cache meta")
|
||||||
}
|
}
|
||||||
|
if c.Cache.CacheControl == "" {
|
||||||
|
c.Cache.CacheControl = "public, max-age=86400"
|
||||||
|
}
|
||||||
rel := pkg.ServerOptions{
|
rel := pkg.ServerOptions{
|
||||||
Domain: c.Domain,
|
Domain: c.Domain,
|
||||||
DefaultBranch: c.Page.DefaultBranch,
|
DefaultBranch: c.Page.DefaultBranch,
|
||||||
Alias: alias,
|
Alias: alias,
|
||||||
CacheMeta: cacheMeta,
|
CacheMeta: cacheMeta,
|
||||||
CacheMetaTTL: c.Cache.MetaTTL,
|
CacheMetaTTL: c.Cache.MetaTTL,
|
||||||
|
CacheControl: c.Cache.CacheControl,
|
||||||
CacheBlob: memoryCache,
|
CacheBlob: memoryCache,
|
||||||
CacheBlobTTL: c.Cache.BlobTTL,
|
CacheBlobTTL: c.Cache.BlobTTL,
|
||||||
CacheBlobLimit: uint64(c.Cache.BlobLimit),
|
CacheBlobLimit: uint64(c.Cache.BlobLimit),
|
||||||
@@ -167,9 +171,10 @@ type ConfigCache struct {
|
|||||||
Meta string `yaml:"meta"` // 元数据缓存
|
Meta string `yaml:"meta"` // 元数据缓存
|
||||||
MetaTTL time.Duration `yaml:"meta_ttl"` // 缓存时间
|
MetaTTL time.Duration `yaml:"meta_ttl"` // 缓存时间
|
||||||
|
|
||||||
Blob string `yaml:"blob"` // 缓存归档位置
|
Blob string `yaml:"blob"` // 缓存归档位置
|
||||||
BlobTTL time.Duration `yaml:"blob_ttl"` // 缓存归档位置
|
BlobTTL time.Duration `yaml:"blob_ttl"` // 缓存归档位置
|
||||||
BlobLimit units.Base2Bytes `yaml:"blob_limit"` // 单个文件最大大小
|
BlobLimit units.Base2Bytes `yaml:"blob_limit"` // 单个文件最大大小
|
||||||
|
CacheControl string `yaml:"cache_control"` // 缓存配置
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig(path string) (*Config, error) {
|
func LoadConfig(path string) (*Config, error) {
|
||||||
|
|||||||
@@ -40,17 +40,18 @@ type ServerOptions struct {
|
|||||||
CacheMeta kv.KV // 配置缓存
|
CacheMeta kv.KV // 配置缓存
|
||||||
CacheMetaTTL time.Duration // 配置缓存时长
|
CacheMetaTTL time.Duration // 配置缓存时长
|
||||||
|
|
||||||
CacheBlob cache.Cache // blob缓存
|
CacheBlob cache.Cache // blob缓存
|
||||||
CacheBlobTTL time.Duration // 配置缓存时长
|
CacheBlobTTL time.Duration // 配置缓存时长
|
||||||
CacheBlobLimit uint64 // blob最大缓存大小
|
CacheControl string // 缓存配置
|
||||||
|
|
||||||
HTTPClient *http.Client // 自定义客户端
|
CacheBlobLimit uint64 // blob最大缓存大小
|
||||||
|
|
||||||
EnableRender bool // 允许渲染
|
HTTPClient *http.Client // 自定义客户端
|
||||||
EnableProxy bool // 允许代理
|
EnableRender bool // 允许渲染
|
||||||
|
|
||||||
StaticDir string // 静态文件位置
|
EnableProxy bool // 允许代理
|
||||||
|
|
||||||
|
StaticDir string // 静态文件位置
|
||||||
DefaultErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
|
DefaultErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +69,7 @@ func DefaultOptions(domain string) ServerOptions {
|
|||||||
CacheBlob: cacheMemory,
|
CacheBlob: cacheMemory,
|
||||||
CacheBlobTTL: time.Minute,
|
CacheBlobTTL: time.Minute,
|
||||||
CacheBlobLimit: 1024 * 1024 * 10,
|
CacheBlobLimit: 1024 * 1024 * 10,
|
||||||
|
CacheControl: "public, max-age=86400",
|
||||||
|
|
||||||
HTTPClient: http.DefaultClient,
|
HTTPClient: http.DefaultClient,
|
||||||
|
|
||||||
@@ -243,7 +245,7 @@ func (s *Server) Serve(writer http.ResponseWriter, request *http.Request) error
|
|||||||
if reader, ok := result.(*cache.Content); ok {
|
if reader, ok := result.(*cache.Content); ok {
|
||||||
writer.Header().Add("X-Cache", "HIT")
|
writer.Header().Add("X-Cache", "HIT")
|
||||||
writer.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(fileName)))
|
writer.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(fileName)))
|
||||||
writer.Header().Add("Cache-Control", "public, max-age=86400")
|
writer.Header().Add("Cache-Control", s.options.CacheControl)
|
||||||
if render != nil {
|
if render != nil {
|
||||||
if err = render.Render(writer, request, reader); err != nil {
|
if err = render.Render(writer, request, reader); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -257,7 +259,6 @@ func (s *Server) Serve(writer http.ResponseWriter, request *http.Request) error
|
|||||||
}
|
}
|
||||||
// todo(bug) : 直连模式下告知数据长度
|
// todo(bug) : 直连模式下告知数据长度
|
||||||
writer.Header().Add("X-Cache", "MISS")
|
writer.Header().Add("X-Cache", "MISS")
|
||||||
writer.Header().Add("Cache-Control", "public, max-age=86400")
|
|
||||||
writer.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(fileName)))
|
writer.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(fileName)))
|
||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
if render != nil {
|
if render != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user