summaryrefslogtreecommitdiff
path: root/plugins/config
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-21 19:42:23 +0300
committerValery Piashchynski <[email protected]>2020-12-21 19:42:23 +0300
commitee8b4075c0f836d698d1ae505c87c17147de447a (patch)
tree531d980e5bfb94ee39b03952a97e0445f7955409 /plugins/config
parent0ad45031047bb479e06ce0a0f496c6db9b2641c9 (diff)
Move plugins to the roadrunner-plugins repository
Diffstat (limited to 'plugins/config')
-rwxr-xr-xplugins/config/plugin.go70
-rwxr-xr-xplugins/config/tests/.rr.yaml18
-rwxr-xr-xplugins/config/tests/config_test.go66
-rwxr-xr-xplugins/config/tests/plugin1.go53
4 files changed, 0 insertions, 207 deletions
diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go
deleted file mode 100755
index 4cde314d..00000000
--- a/plugins/config/plugin.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package config
-
-import (
- "bytes"
- "errors"
- "strings"
-
- "github.com/spf13/viper"
-)
-
-type Viper struct {
- viper *viper.Viper
- Path string
- Prefix string
- ReadInCfg []byte
-}
-
-// Inits config provider.
-func (v *Viper) Init() error {
- v.viper = viper.New()
-
- // read in environment variables that match
- v.viper.AutomaticEnv()
- if v.Prefix == "" {
- return errors.New("prefix should be set")
- }
-
- v.viper.SetEnvPrefix(v.Prefix)
- if v.Path == "" {
- return errors.New("path should be set")
- }
-
- v.viper.SetConfigFile(v.Path)
- v.viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
-
- if v.ReadInCfg != nil {
- return v.viper.ReadConfig(bytes.NewBuffer(v.ReadInCfg))
- }
- return v.viper.ReadInConfig()
-}
-
-// Overwrite overwrites existing config with provided values
-func (v *Viper) Overwrite(values map[string]interface{}) error {
- if len(values) != 0 {
- for key, value := range values {
- v.viper.Set(key, value)
- }
- }
-
- return nil
-}
-
-// UnmarshalKey reads configuration section into configuration object.
-func (v *Viper) UnmarshalKey(name string, out interface{}) error {
- err := v.viper.UnmarshalKey(name, &out)
- if err != nil {
- return err
- }
- return nil
-}
-
-// Get raw config in a form of config section.
-func (v *Viper) Get(name string) interface{} {
- return v.viper.Get(name)
-}
-
-// Has checks if config section exists.
-func (v *Viper) Has(name string) bool {
- return v.viper.IsSet(name)
-}
diff --git a/plugins/config/tests/.rr.yaml b/plugins/config/tests/.rr.yaml
deleted file mode 100755
index 732a1366..00000000
--- a/plugins/config/tests/.rr.yaml
+++ /dev/null
@@ -1,18 +0,0 @@
-reload:
- enabled: true
- interval: 1s
- patterns: [".php"]
- services:
- http:
- recursive: true
- ignore: ["vendor"]
- patterns: [".php", ".go",".md",]
- dirs: ["."]
- jobs:
- recursive: false
- ignore: ["service/metrics"]
- dirs: ["./jobs"]
- rpc:
- recursive: true
- patterns: [".json"]
- dirs: [""]
diff --git a/plugins/config/tests/config_test.go b/plugins/config/tests/config_test.go
deleted file mode 100755
index 91ddc4ae..00000000
--- a/plugins/config/tests/config_test.go
+++ /dev/null
@@ -1,66 +0,0 @@
-package tests
-
-import (
- "os"
- "os/signal"
- "testing"
- "time"
-
- "github.com/spiral/endure"
- "github.com/spiral/roadrunner/v2/plugins/config"
- "github.com/stretchr/testify/assert"
-)
-
-func TestViperProvider_Init(t *testing.T) {
- container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
- if err != nil {
- t.Fatal(err)
- }
- vp := &config.Viper{}
- vp.Path = ".rr.yaml"
- vp.Prefix = "rr"
- err = container.Register(vp)
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Register(&Foo{})
- if err != nil {
- t.Fatal(err)
- }
-
- err = container.Init()
- if err != nil {
- t.Fatal(err)
- }
-
- errCh, err := container.Serve()
- if err != nil {
- t.Fatal(err)
- }
-
- // stop by CTRL+C
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt)
-
- tt := time.NewTicker(time.Second * 2)
-
- for {
- select {
- case e := <-errCh:
- assert.NoError(t, e.Error)
- assert.NoError(t, container.Stop())
- return
- case <-c:
- er := container.Stop()
- if er != nil {
- panic(er)
- }
- return
- case <-tt.C:
- tt.Stop()
- assert.NoError(t, container.Stop())
- return
- }
- }
-}
diff --git a/plugins/config/tests/plugin1.go b/plugins/config/tests/plugin1.go
deleted file mode 100755
index 724afbd4..00000000
--- a/plugins/config/tests/plugin1.go
+++ /dev/null
@@ -1,53 +0,0 @@
-package tests
-
-import (
- "errors"
- "time"
-
- "github.com/spiral/roadrunner/v2/interfaces/config"
-)
-
-// ReloadConfig is a Reload configuration point.
-type ReloadConfig struct {
- Interval time.Duration
- Patterns []string
- Services map[string]ServiceConfig
-}
-
-type ServiceConfig struct {
- Enabled bool
- Recursive bool
- Patterns []string
- Dirs []string
- Ignore []string
-}
-
-type Foo struct {
- configProvider config.Configurer
-}
-
-// Depends on S2 and DB (S3 in the current case)
-func (f *Foo) Init(p config.Configurer) error {
- f.configProvider = p
- return nil
-}
-
-func (f *Foo) Serve() chan error {
- errCh := make(chan error, 1)
-
- r := &ReloadConfig{}
- err := f.configProvider.UnmarshalKey("reload", r)
- if err != nil {
- errCh <- err
- }
-
- if len(r.Patterns) == 0 {
- errCh <- errors.New("should be at least one pattern, but got 0")
- }
-
- return errCh
-}
-
-func (f *Foo) Stop() error {
- return nil
-}