-
Notifications
You must be signed in to change notification settings - Fork 31
/
hooks.go
47 lines (39 loc) · 893 Bytes
/
hooks.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 libbuildpack
import (
"sync"
)
type Hook interface {
BeforeCompile(*Stager) error
AfterCompile(*Stager) error
}
var hookArray []Hook
var hookArrayLock sync.Mutex
func AddHook(hook Hook) {
hookArrayLock.Lock()
hookArray = append(hookArray, hook)
hookArrayLock.Unlock()
}
func ClearHooks() {
hookArrayLock.Lock()
hookArray = make([]Hook, 0)
hookArrayLock.Unlock()
}
func RunBeforeCompile(stager *Stager) error {
for _, hook := range hookArray {
if err := hook.BeforeCompile(stager); err != nil {
return err
}
}
return nil
}
func RunAfterCompile(stager *Stager) error {
for _, hook := range hookArray {
if err := hook.AfterCompile(stager); err != nil {
return err
}
}
return nil
}
type DefaultHook struct{}
func (d DefaultHook) BeforeCompile(stager *Stager) error { return nil }
func (d DefaultHook) AfterCompile(stager *Stager) error { return nil }