summaryrefslogtreecommitdiff
path: root/service/limit/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'service/limit/config.go')
-rw-r--r--service/limit/config.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/service/limit/config.go b/service/limit/config.go
new file mode 100644
index 00000000..bf842ac2
--- /dev/null
+++ b/service/limit/config.go
@@ -0,0 +1,48 @@
+package limit
+
+import (
+ "github.com/spiral/roadrunner"
+ "github.com/spiral/roadrunner/service"
+ "time"
+)
+
+// Configures set of Services.
+type Config struct {
+ // Interval defines the update duration for underlying controllers, default 1s.
+ Interval time.Duration
+
+ // Services declares list of services to be watched.
+ Services map[string]*controllerConfig
+}
+
+// Hydrate must populate Config values using given Config source. Must return error if Config is not valid.
+func (c *Config) Hydrate(cfg service.Config) error {
+ if err := cfg.Unmarshal(c); err != nil {
+ return err
+ }
+
+ // Always use second based definition for time durations
+ if c.Interval < time.Microsecond {
+ c.Interval = time.Second * time.Duration(c.Interval.Nanoseconds())
+ }
+
+ return nil
+}
+
+// InitDefaults sets missing values to their default values.
+func (c *Config) InitDefaults() error {
+ c.Interval = time.Second
+
+ return nil
+}
+
+// Controllers returns list of defined Services
+func (c *Config) Controllers(l listener) (controllers map[string]roadrunner.Controller) {
+ controllers = make(map[string]roadrunner.Controller)
+
+ for name, cfg := range c.Services {
+ controllers[name] = &controller{lsn: l, tick: c.Interval, cfg: cfg}
+ }
+
+ return controllers
+}