/
manager.go
47 lines (38 loc) · 1.48 KB
/
manager.go
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
package manager
import (
"encoding/json"
"github.com/caraml-dev/turing/engines/experiment/manager"
"github.com/caraml-dev/turing/engines/experiment/plugin/rpc/shared"
)
// ConfigurableExperimentManager interface of an ExperimentManager, that can be configured
// with an arbitrary configuration passed as a JSON data
type ConfigurableExperimentManager interface {
shared.Configurable
manager.ExperimentManager
}
func NewConfigurableStandardExperimentManager(
factory func(cfg json.RawMessage) (manager.StandardExperimentManager, error),
) ConfigurableExperimentManager {
return &configurableStandardExperimentManager{factory: factory}
}
type configurableStandardExperimentManager struct {
manager.StandardExperimentManager
factory func(cfg json.RawMessage) (manager.StandardExperimentManager, error)
}
func (em *configurableStandardExperimentManager) Configure(cfg json.RawMessage) (err error) {
em.StandardExperimentManager, err = em.factory(cfg)
return
}
func NewConfigurableCustomExperimentManager(
factory func(cfg json.RawMessage) (manager.CustomExperimentManager, error),
) ConfigurableExperimentManager {
return &configurableCustomExperimentManager{factory: factory}
}
type configurableCustomExperimentManager struct {
manager.CustomExperimentManager
factory func(cfg json.RawMessage) (manager.CustomExperimentManager, error)
}
func (em *configurableCustomExperimentManager) Configure(cfg json.RawMessage) (err error) {
em.CustomExperimentManager, err = em.factory(cfg)
return
}