diff options
author | Valery Piashchynski <[email protected]> | 2021-01-15 00:29:23 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-01-15 00:29:23 +0300 |
commit | aff4d2c7a92ae014988b27b27069b15a971b6c36 (patch) | |
tree | 50dc6e22db7ff51b0fcf3cce0a45b7b739e1f300 /plugins/http | |
parent | 7542ae2d4c392290766405d31996378378aad975 (diff) |
Viper doesn't support `yaml` structure tags, it uses mapstructure
instead
Diffstat (limited to 'plugins/http')
-rw-r--r-- | plugins/http/config.go | 8 | ||||
-rw-r--r-- | plugins/http/handler.go | 2 | ||||
-rw-r--r-- | plugins/http/plugin.go | 18 |
3 files changed, 11 insertions, 17 deletions
diff --git a/plugins/http/config.go b/plugins/http/config.go index abde8917..e272e550 100644 --- a/plugins/http/config.go +++ b/plugins/http/config.go @@ -49,16 +49,16 @@ type Config struct { HTTP2 *HTTP2Config // MaxRequestSize specified max size for payload body in megabytes, set 0 to unlimited. - MaxRequestSize uint64 `yaml:"max_request_size"` + MaxRequestSize uint64 `mapstructure:"max_request_size"` // TrustedSubnets declare IP subnets which are allowed to set ip using X-Real-Ip and X-Forwarded-For - TrustedSubnets []string `yaml:"trusted_subnets"` + TrustedSubnets []string `mapstructure:"trusted_subnets"` // Uploads configures uploads configuration. Uploads *UploadsConfig // Pool configures worker pool. - Pool *poolImpl.Config + Pool *poolImpl.Config `mapstructure:"pool"` // Env is environment variables passed to the http pool Env map[string]string @@ -85,7 +85,7 @@ type HTTP2Config struct { H2C bool // MaxConcurrentStreams defaults to 128. - MaxConcurrentStreams uint32 `yaml:"max_concurrent_streams"` + MaxConcurrentStreams uint32 `mapstructure:"max_concurrent_streams"` } // InitDefaults sets default values for HTTP/2 configuration. diff --git a/plugins/http/handler.go b/plugins/http/handler.go index 9c40cdfc..1c7f79e3 100644 --- a/plugins/http/handler.go +++ b/plugins/http/handler.go @@ -24,7 +24,7 @@ const ( ) // MB is 1024 bytes -const MB = 1024 * 1024 +const MB uint64 = 1024 * 1024 // ErrorEvent represents singular http error event. type ErrorEvent struct { diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go index e6aba78b..70e91cbe 100644 --- a/plugins/http/plugin.go +++ b/plugins/http/plugin.go @@ -48,11 +48,11 @@ type middleware map[string]Middleware type Plugin struct { sync.RWMutex - configurer config.Configurer - server server.Server - log logger.Logger + // plugins + server server.Server + log logger.Logger - cfg *Config + cfg *Config `mapstructure:"http"` // middlewares to chain mdwr middleware @@ -71,7 +71,7 @@ type Plugin struct { // Init must return configure svc and return true if svc hasStatus enabled. Must return error in case of // misconfiguration. Services must not be used without proper configuration pushed first. func (s *Plugin) Init(cfg config.Configurer, log logger.Logger, server server.Server) error { - const op = errors.Op("http Init") + const op = errors.Op("http plugin init") err := cfg.UnmarshalKey(PluginName, &s.cfg) if err != nil { return errors.E(op, err) @@ -82,7 +82,6 @@ func (s *Plugin) Init(cfg config.Configurer, log logger.Logger, server server.Se return errors.E(op, err) } - s.configurer = cfg s.log = log s.mdwr = make(map[string]Middleware) @@ -286,12 +285,7 @@ func (s *Plugin) Reset() error { s.pool.Destroy(context.Background()) s.pool = nil - // re-read the config - err := s.configurer.UnmarshalKey(PluginName, &s.cfg) - if err != nil { - return errors.E(op, err) - } - + var err error s.pool, err = s.server.NewWorkerPool(context.Background(), poolImpl.Config{ Debug: s.cfg.Pool.Debug, NumWorkers: s.cfg.Pool.NumWorkers, |