-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_code.go
More file actions
36 lines (29 loc) · 782 Bytes
/
source_code.go
File metadata and controls
36 lines (29 loc) · 782 Bytes
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
package adapt
import "log/slog"
type codeSource struct {
m map[string]Hook
list []string
}
// NewCodeSource provides a new HookSource for the single id-hook pair passed
// to it.
func NewCodeSource(id string, hook Hook) HookSource {
return NewCodePackageSource(map[string]Hook{id: hook})
}
// NewCodePackageSource provides a new HookSource for the map of id-hook pairs
// passed to it.
func NewCodePackageSource(pkg map[string]Hook) HookSource {
src := &codeSource{m: pkg}
for key := range pkg {
src.list = append(src.list, key)
}
return src
}
func (src *codeSource) Init(_ *slog.Logger) error {
return nil
}
func (src *codeSource) ListMigrations() ([]string, error) {
return src.list, nil
}
func (src *codeSource) GetHook(id string) Hook {
return src.m[id]
}