diff options
author | Wolfy-J <[email protected]> | 2018-07-26 16:32:27 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-07-26 16:32:27 +0300 |
commit | bcef5b36bb50b2fecd4db4ca8e01640347300bea (patch) | |
tree | b6db6954063dd3288a80f24aa714e8799664d909 /service/env | |
parent | 0f8e2bab6888f1b27ed2bd1b91ac6b2677f03450 (diff) |
- added support for custom env provider
- new config section "env" to share env variables with php process
- container can resolve interfaces now
Diffstat (limited to 'service/env')
-rw-r--r-- | service/env/config.go | 17 | ||||
-rw-r--r-- | service/env/provider.go | 8 | ||||
-rw-r--r-- | service/env/service.go | 21 |
3 files changed, 46 insertions, 0 deletions
diff --git a/service/env/config.go b/service/env/config.go new file mode 100644 index 00000000..06342f98 --- /dev/null +++ b/service/env/config.go @@ -0,0 +1,17 @@ +package env + +import ( + "github.com/spiral/roadrunner/service" +) + +// Config defines set of env values for RR workers. +type Config struct { + // Values to set as worker _ENV. + Values map[string]string +} + +// 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 { + c.Values = map[string]string{"RR": "YES"} + return cfg.Unmarshal(&c.Values) +} diff --git a/service/env/provider.go b/service/env/provider.go new file mode 100644 index 00000000..75a1e31b --- /dev/null +++ b/service/env/provider.go @@ -0,0 +1,8 @@ +package env + +// Provider aggregates list of environment variables. This interface can be used in custom implementation to drive +// values from external sources. +type Provider interface { + // GetEnv must return list of env variables. + GetEnv() map[string]string +} diff --git a/service/env/service.go b/service/env/service.go new file mode 100644 index 00000000..95e99093 --- /dev/null +++ b/service/env/service.go @@ -0,0 +1,21 @@ +package env + +// ID contains default svc name. +const ID = "env" + +// Service provides ability to map _ENV values from config file. +type Service struct { + cfg *Config +} + +// 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 *Service) Init(cfg *Config) (bool, error) { + s.cfg = cfg + return true, nil +} + +// GetEnv must return list of env variables. +func (s *Service) GetEnv() map[string]string { + return s.cfg.Values +} |