Skip to content

Commit

Permalink
feat: Allow to configure compress middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyno-zeta committed Mar 7, 2021
1 parent a1dc2e3 commit 097c776
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 64 deletions.
36 changes: 32 additions & 4 deletions pkg/s3-proxy/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ import (
// DefaultPort Default port.
const DefaultPort = 8080

// DefaultServerCompressEnabled Default server compress enabled.
var DefaultServerCompressEnabled bool = true

// DefaultServerCompressLevel Default server compress level.
const DefaultServerCompressLevel = 5

// DefaultServerCompressTypes Default server compress types.
var DefaultServerCompressTypes = []string{
"text/html",
"text/css",
"text/plain",
"text/javascript",
"application/javascript",
"application/x-javascript",
"application/json",
"application/atom+xml",
"application/rss+xml",
"image/svg+xml",
}

// DefaultInternalPort Default internal port.
const DefaultInternalPort = 9090

Expand Down Expand Up @@ -153,10 +173,18 @@ type TemplateConfig struct {

// ServerConfig Server configuration.
type ServerConfig struct {
ListenAddr string `mapstructure:"listenAddr"`
Port int `mapstructure:"port" validate:"required"`
CORS *ServerCorsConfig `mapstructure:"cors" validate:"omitempty"`
Cache *CacheConfig `mapstructure:"cache" validate:"omitempty"`
ListenAddr string `mapstructure:"listenAddr"`
Port int `mapstructure:"port" validate:"required"`
CORS *ServerCorsConfig `mapstructure:"cors" validate:"omitempty"`
Cache *CacheConfig `mapstructure:"cache" validate:"omitempty"`
Compress *ServerCompressConfig `mapstructure:"compress" validate:"omitempty"`
}

// ServerCompressConfig Server compress configuration.
type ServerCompressConfig struct {
Enabled *bool `mapstructure:"enabled"`
Level int `mapstructure:"level" validate:"required,min=1"`
Types []string `mapstructure:"types" validate:"required,min=1"`
}

// CacheConfig Cache configuration.
Expand Down
6 changes: 6 additions & 0 deletions pkg/s3-proxy/config/managercontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ func (ctx *managercontext) loadDefaultConfigurationValues(vip *viper.Viper) {
vip.SetDefault("log.level", DefaultLogLevel)
vip.SetDefault("log.format", DefaultLogFormat)
vip.SetDefault("server.port", DefaultPort)
vip.SetDefault("server.compress.enabled", &DefaultServerCompressEnabled)
vip.SetDefault("server.compress.level", DefaultServerCompressLevel)
vip.SetDefault("server.compress.types", DefaultServerCompressTypes)
vip.SetDefault("internalServer.port", DefaultInternalPort)
vip.SetDefault("internalServer.compress.enabled", &DefaultServerCompressEnabled)
vip.SetDefault("internalServer.compress.level", DefaultServerCompressLevel)
vip.SetDefault("internalServer.compress.types", DefaultServerCompressTypes)
vip.SetDefault("templates.folderList", DefaultTemplateFolderListPath)
vip.SetDefault("templates.targetList", DefaultTemplateTargetListPath)
vip.SetDefault("templates.notFound", DefaultTemplateNotFoundPath)
Expand Down
Loading

0 comments on commit 097c776

Please # to comment.