-
Notifications
You must be signed in to change notification settings - Fork 10
/
hook.go
49 lines (40 loc) · 1.15 KB
/
hook.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
48
49
package manager
import (
"github.com/freakmaxi/kertish-dfs/basics/hooks"
"github.com/freakmaxi/kertish-dfs/head-node/data"
"go.uber.org/zap"
)
// Hook interface is for hook manipulation operations base on REST service request
type Hook interface {
GetAvailableList() []interface{}
Add(folderPaths []string, hook *hooks.Hook) error
Delete(folderPath string, hookIds []string) error
}
type hook struct {
metadata data.Metadata
logger *zap.Logger
}
// NewHook creates the instance of hook manipulation operations object for REST service request
func NewHook(metadata data.Metadata, logger *zap.Logger) Hook {
return &hook{
metadata: metadata,
logger: logger,
}
}
func (h *hook) GetAvailableList() []interface{} {
availableHooks := make([]interface{}, 0)
actions := hooks.CurrentLoader.List()
for _, action := range actions {
availableHooks = append(availableHooks, &struct {
Provider string `json:"provider"`
Version string `json:"version"`
Sample interface{} `json:"sample"`
}{
Provider: action.Provider(),
Version: action.Version(),
Sample: action.Sample(),
})
}
return availableHooks
}
var _ Hook = &hook{}