summaryrefslogtreecommitdiff
path: root/plugins/config/tests/plugin1.go
blob: 7b5d6bd8319d869e72bf3981dcf5187447fd9717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package tests

import (
	"errors"
	"time"

	config2 "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 config2.Configurer
}

// Depends on S2 and DB (S3 in the current case)
func (f *Foo) Init(p config2.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
}