summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/http/config.go8
-rw-r--r--plugins/http/handler.go2
-rw-r--r--plugins/http/plugin.go18
-rw-r--r--plugins/kv/boltdb/config.go2
-rw-r--r--plugins/logger/config.go12
-rw-r--r--plugins/redis/config.go42
-rw-r--r--plugins/server/config.go188
-rw-r--r--plugins/server/plugin.go2
8 files changed, 134 insertions, 140 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,
diff --git a/plugins/kv/boltdb/config.go b/plugins/kv/boltdb/config.go
index b2e1e636..ea0e3375 100644
--- a/plugins/kv/boltdb/config.go
+++ b/plugins/kv/boltdb/config.go
@@ -11,7 +11,7 @@ type Config struct {
// db file permissions
Permissions int
// timeout
- Interval uint `yaml:"interval"`
+ Interval uint `mapstructure:"interval"`
}
// InitDefaults initializes default values for the boltdb
diff --git a/plugins/logger/config.go b/plugins/logger/config.go
index f7a5742c..8cc88d02 100644
--- a/plugins/logger/config.go
+++ b/plugins/logger/config.go
@@ -10,26 +10,26 @@ import (
// ChannelConfig configures loggers per channel.
type ChannelConfig struct {
// Dedicated channels per logger. By default logger allocated via named logger.
- Channels map[string]Config `json:"channels" yaml:"channels"`
+ Channels map[string]Config `json:"channels" mapstructure:"channels"`
}
type Config struct {
// Mode configures logger based on some default template (development, production, off).
- Mode string `json:"mode" yaml:"mode"`
+ Mode string `json:"mode" mapstructure:"mode"`
// Level is the minimum enabled logging level. Note that this is a dynamic
// level, so calling ChannelConfig.Level.SetLevel will atomically change the log
// level of all loggers descended from this config.
- Level string `json:"level" yaml:"level"`
+ Level string `json:"level" mapstructure:"level"`
// Encoding sets the logger's encoding. Valid values are "json" and
// "console", as well as any third-party encodings registered via
// RegisterEncoder.
- Encoding string `json:"encoding" yaml:"encoding"`
+ Encoding string `json:"encoding" mapstructure:"encoding"`
// Output is a list of URLs or file paths to write logging output to.
// See Open for details.
- Output []string `json:"output" yaml:"output"`
+ Output []string `json:"output" mapstructure:"output"`
// ErrorOutput is a list of URLs to write internal logger errors to.
// The default is standard error.
@@ -37,7 +37,7 @@ type Config struct {
// Note that this setting only affects internal errors; for sample code that
// sends error-level logs to a different location from info- and debug-level
// logs, see the package-level AdvancedConfiguration example.
- ErrorOutput []string `json:"errorOutput" yaml:"errorOutput"`
+ ErrorOutput []string `json:"errorOutput" mapstructure:"errorOutput"`
}
// ZapConfig converts config into Zap configuration.
diff --git a/plugins/redis/config.go b/plugins/redis/config.go
index ebcefed1..58766293 100644
--- a/plugins/redis/config.go
+++ b/plugins/redis/config.go
@@ -3,27 +3,27 @@ package redis
import "time"
type Config struct {
- Addrs []string `yaml:"addrs"`
- DB int `yaml:"db"`
- Username string `yaml:"username"`
- Password string `yaml:"password"`
- MasterName string `yaml:"master_name"`
- SentinelPassword string `yaml:"sentinel_password"`
- RouteByLatency bool `yaml:"route_by_latency"`
- RouteRandomly bool `yaml:"route_randomly"`
- MaxRetries int `yaml:"max_retries"`
- DialTimeout time.Duration `yaml:"dial_timeout"`
- MinRetryBackoff time.Duration `yaml:"min_retry_backoff"`
- MaxRetryBackoff time.Duration `yaml:"max_retry_backoff"`
- PoolSize int `yaml:"pool_size"`
- MinIdleConns int `yaml:"min_idle_conns"`
- MaxConnAge time.Duration `yaml:"max_conn_age"`
- ReadTimeout time.Duration `yaml:"read_timeout"`
- WriteTimeout time.Duration `yaml:"write_timeout"`
- PoolTimeout time.Duration `yaml:"pool_timeout"`
- IdleTimeout time.Duration `yaml:"idle_timeout"`
- IdleCheckFreq time.Duration `yaml:"idle_check_freq"`
- ReadOnly bool `yaml:"read_only"`
+ Addrs []string `mapstructure:"addrs"`
+ DB int `mapstructure:"db"`
+ Username string `mapstructure:"username"`
+ Password string `mapstructure:"password"`
+ MasterName string `mapstructure:"master_name"`
+ SentinelPassword string `mapstructure:"sentinel_password"`
+ RouteByLatency bool `mapstructure:"route_by_latency"`
+ RouteRandomly bool `mapstructure:"route_randomly"`
+ MaxRetries int `mapstructure:"max_retries"`
+ DialTimeout time.Duration `mapstructure:"dial_timeout"`
+ MinRetryBackoff time.Duration `mapstructure:"min_retry_backoff"`
+ MaxRetryBackoff time.Duration `mapstructure:"max_retry_backoff"`
+ PoolSize int `mapstructure:"pool_size"`
+ MinIdleConns int `mapstructure:"min_idle_conns"`
+ MaxConnAge time.Duration `mapstructure:"max_conn_age"`
+ ReadTimeout time.Duration `mapstructure:"read_timeout"`
+ WriteTimeout time.Duration `mapstructure:"write_timeout"`
+ PoolTimeout time.Duration `mapstructure:"pool_timeout"`
+ IdleTimeout time.Duration `mapstructure:"idle_timeout"`
+ IdleCheckFreq time.Duration `mapstructure:"idle_check_freq"`
+ ReadOnly bool `mapstructure:"read_only"`
}
// InitDefaults initializing fill config with default values
diff --git a/plugins/server/config.go b/plugins/server/config.go
index a990efd3..93b19226 100644
--- a/plugins/server/config.go
+++ b/plugins/server/config.go
@@ -10,129 +10,129 @@ type Config struct {
// Server config section
Server struct {
// Command to run as application.
- Command string `yaml:"command"`
+ Command string `mapstructure:"command"`
// User to run application under.
- User string `yaml:"user"`
+ User string `mapstructure:"user"`
// Group to run application under.
- Group string `yaml:"group"`
+ Group string `mapstructure:"group"`
// Env represents application environment.
- Env Env `yaml:"env"`
+ Env Env `mapstructure:"env"`
// Relay defines connection method and factory to be used to connect to workers:
// "pipes", "tcp://:6001", "unix://rr.sock"
// This config section must not change on re-configuration.
- Relay string `yaml:"relay"`
+ Relay string `mapstructure:"relay"`
// RelayTimeout defines for how long socket factory will be waiting for worker connection. This config section
// must not change on re-configuration. Defaults to 60s.
- RelayTimeout time.Duration `yaml:"relayTimeout"`
- } `yaml:"server"`
+ RelayTimeout time.Duration `mapstructure:"relayTimeout"`
+ } `mapstructure:"server"`
RPC *struct {
- Listen string `yaml:"listen"`
- } `yaml:"rpc"`
+ Listen string `mapstructure:"listen"`
+ } `mapstructure:"rpc"`
Logs *struct {
- Mode string `yaml:"mode"`
- Level string `yaml:"level"`
- } `yaml:"logs"`
+ Mode string `mapstructure:"mode"`
+ Level string `mapstructure:"level"`
+ } `mapstructure:"logs"`
HTTP *struct {
- Address string `yaml:"address"`
- MaxRequestSize int `yaml:"max_request_size"`
- Middleware []string `yaml:"middleware"`
+ Address string `mapstructure:"address"`
+ MaxRequestSize int `mapstructure:"max_request_size"`
+ Middleware []string `mapstructure:"middleware"`
Uploads struct {
- Forbid []string `yaml:"forbid"`
- } `yaml:"uploads"`
- TrustedSubnets []string `yaml:"trusted_subnets"`
+ Forbid []string `mapstructure:"forbid"`
+ } `mapstructure:"uploads"`
+ TrustedSubnets []string `mapstructure:"trusted_subnets"`
Pool struct {
- NumWorkers int `yaml:"num_workers"`
- MaxJobs int `yaml:"max_jobs"`
- AllocateTimeout string `yaml:"allocate_timeout"`
- DestroyTimeout string `yaml:"destroy_timeout"`
+ NumWorkers int `mapstructure:"num_workers"`
+ MaxJobs int `mapstructure:"max_jobs"`
+ AllocateTimeout string `mapstructure:"allocate_timeout"`
+ DestroyTimeout string `mapstructure:"destroy_timeout"`
Supervisor struct {
- WatchTick int `yaml:"watch_tick"`
- TTL int `yaml:"ttl"`
- IdleTTL int `yaml:"idle_ttl"`
- ExecTTL int `yaml:"exec_ttl"`
- MaxWorkerMemory int `yaml:"max_worker_memory"`
- } `yaml:"supervisor"`
- } `yaml:"pool"`
+ WatchTick int `mapstructure:"watch_tick"`
+ TTL int `mapstructure:"ttl"`
+ IdleTTL int `mapstructure:"idle_ttl"`
+ ExecTTL int `mapstructure:"exec_ttl"`
+ MaxWorkerMemory int `mapstructure:"max_worker_memory"`
+ } `mapstructure:"supervisor"`
+ } `mapstructure:"pool"`
Ssl struct {
- Port int `yaml:"port"`
- Redirect bool `yaml:"redirect"`
- Cert string `yaml:"cert"`
- Key string `yaml:"key"`
- } `yaml:"ssl"`
+ Port int `mapstructure:"port"`
+ Redirect bool `mapstructure:"redirect"`
+ Cert string `mapstructure:"cert"`
+ Key string `mapstructure:"key"`
+ } `mapstructure:"ssl"`
Fcgi struct {
- Address string `yaml:"address"`
- } `yaml:"fcgi"`
+ Address string `mapstructure:"address"`
+ } `mapstructure:"fcgi"`
HTTP2 struct {
- Enabled bool `yaml:"enabled"`
- H2C bool `yaml:"h2c"`
- MaxConcurrentStreams int `yaml:"max_concurrent_streams"`
- } `yaml:"http2"`
- } `yaml:"http"`
+ Enabled bool `mapstructure:"enabled"`
+ H2C bool `mapstructure:"h2c"`
+ MaxConcurrentStreams int `mapstructure:"max_concurrent_streams"`
+ } `mapstructure:"http2"`
+ } `mapstructure:"http"`
Redis *struct {
- Addrs []string `yaml:"addrs"`
- MasterName string `yaml:"master_name"`
- Username string `yaml:"username"`
- Password string `yaml:"password"`
- DB int `yaml:"db"`
- SentinelPassword string `yaml:"sentinel_password"`
- RouteByLatency bool `yaml:"route_by_latency"`
- RouteRandomly bool `yaml:"route_randomly"`
- DialTimeout int `yaml:"dial_timeout"`
- MaxRetries int `yaml:"max_retries"`
- MinRetryBackoff int `yaml:"min_retry_backoff"`
- MaxRetryBackoff int `yaml:"max_retry_backoff"`
- PoolSize int `yaml:"pool_size"`
- MinIdleConns int `yaml:"min_idle_conns"`
- MaxConnAge int `yaml:"max_conn_age"`
- ReadTimeout int `yaml:"read_timeout"`
- WriteTimeout int `yaml:"write_timeout"`
- PoolTimeout int `yaml:"pool_timeout"`
- IdleTimeout int `yaml:"idle_timeout"`
- IdleCheckFreq int `yaml:"idle_check_freq"`
- ReadOnly bool `yaml:"read_only"`
- } `yaml:"redis"`
+ Addrs []string `mapstructure:"addrs"`
+ MasterName string `mapstructure:"master_name"`
+ Username string `mapstructure:"username"`
+ Password string `mapstructure:"password"`
+ DB int `mapstructure:"db"`
+ SentinelPassword string `mapstructure:"sentinel_password"`
+ RouteByLatency bool `mapstructure:"route_by_latency"`
+ RouteRandomly bool `mapstructure:"route_randomly"`
+ DialTimeout int `mapstructure:"dial_timeout"`
+ MaxRetries int `mapstructure:"max_retries"`
+ MinRetryBackoff int `mapstructure:"min_retry_backoff"`
+ MaxRetryBackoff int `mapstructure:"max_retry_backoff"`
+ PoolSize int `mapstructure:"pool_size"`
+ MinIdleConns int `mapstructure:"min_idle_conns"`
+ MaxConnAge int `mapstructure:"max_conn_age"`
+ ReadTimeout int `mapstructure:"read_timeout"`
+ WriteTimeout int `mapstructure:"write_timeout"`
+ PoolTimeout int `mapstructure:"pool_timeout"`
+ IdleTimeout int `mapstructure:"idle_timeout"`
+ IdleCheckFreq int `mapstructure:"idle_check_freq"`
+ ReadOnly bool `mapstructure:"read_only"`
+ } `mapstructure:"redis"`
Boltdb *struct {
- Dir string `yaml:"dir"`
- File string `yaml:"file"`
- Bucket string `yaml:"bucket"`
- Permissions int `yaml:"permissions"`
- TTL int `yaml:"TTL"`
- } `yaml:"boltdb"`
+ Dir string `mapstructure:"dir"`
+ File string `mapstructure:"file"`
+ Bucket string `mapstructure:"bucket"`
+ Permissions int `mapstructure:"permissions"`
+ TTL int `mapstructure:"TTL"`
+ } `mapstructure:"boltdb"`
Memcached *struct {
- Addr []string `yaml:"addr"`
- } `yaml:"memcached"`
+ Addr []string `mapstructure:"addr"`
+ } `mapstructure:"memcached"`
Memory *struct {
- Enabled bool `yaml:"enabled"`
- Interval int `yaml:"interval"`
- } `yaml:"memory"`
+ Enabled bool `mapstructure:"enabled"`
+ Interval int `mapstructure:"interval"`
+ } `mapstructure:"memory"`
Metrics *struct {
- Address string `yaml:"address"`
+ Address string `mapstructure:"address"`
Collect struct {
AppMetric struct {
- Type string `yaml:"type"`
- Help string `yaml:"help"`
- Labels []string `yaml:"labels"`
- Buckets []float64 `yaml:"buckets"`
+ Type string `mapstructure:"type"`
+ Help string `mapstructure:"help"`
+ Labels []string `mapstructure:"labels"`
+ Buckets []float64 `mapstructure:"buckets"`
Objectives []struct {
- Num2 float64 `yaml:"2,omitempty"`
- One4 float64 `yaml:"1.4,omitempty"`
- } `yaml:"objectives"`
- } `yaml:"app_metric"`
- } `yaml:"collect"`
- } `yaml:"metrics"`
+ Num2 float64 `mapstructure:"2,omitempty"`
+ One4 float64 `mapstructure:"1.4,omitempty"`
+ } `mapstructure:"objectives"`
+ } `mapstructure:"app_metric"`
+ } `mapstructure:"collect"`
+ } `mapstructure:"metrics"`
Reload *struct {
- Interval string `yaml:"interval"`
- Patterns []string `yaml:"patterns"`
+ Interval string `mapstructure:"interval"`
+ Patterns []string `mapstructure:"patterns"`
Services struct {
HTTP struct {
- Recursive bool `yaml:"recursive"`
- Ignore []string `yaml:"ignore"`
- Patterns []string `yaml:"patterns"`
- Dirs []string `yaml:"dirs"`
- } `yaml:"http"`
- } `yaml:"services"`
- } `yaml:"reload"`
+ Recursive bool `mapstructure:"recursive"`
+ Ignore []string `mapstructure:"ignore"`
+ Patterns []string `mapstructure:"patterns"`
+ Dirs []string `mapstructure:"dirs"`
+ } `mapstructure:"http"`
+ } `mapstructure:"services"`
+ } `mapstructure:"reload"`
}
// InitDefaults for the server config
diff --git a/plugins/server/plugin.go b/plugins/server/plugin.go
index 565c80c4..8c39b783 100644
--- a/plugins/server/plugin.go
+++ b/plugins/server/plugin.go
@@ -40,7 +40,7 @@ type Plugin struct {
// Init application provider.
func (server *Plugin) Init(cfg config.Configurer, log logger.Logger) error {
- const op = errors.Op("Init")
+ const op = errors.Op("server plugin init")
err := cfg.Unmarshal(&server.cfg)
if err != nil {
return errors.E(op, errors.Init, err)