forked from facebookincubator/go2chef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.go
34 lines (28 loc) · 922 Bytes
/
source.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
package go2chef
/*
Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/
// Source defines the interface for source download components
type Source interface {
Component
DownloadToPath(path string) error
}
// SourceLoader represents factory functions for Sources
type SourceLoader func(map[string]interface{}) (Source, error)
var (
sourceRegistry = make(map[string]SourceLoader)
)
// RegisterSource registers a new source plugin
func RegisterSource(name string, s SourceLoader) {
if _, ok := sourceRegistry[name]; ok {
panic("source plugin " + name + " is already registered")
}
sourceRegistry[name] = s
}
// GetSource gets the specified source plugin configured with the provided config map
func GetSource(name string, config map[string]interface{}) (Source, error) {
if s, ok := sourceRegistry[name]; ok {
return s(config)
}
return nil, &ErrComponentDoesNotExist{Component: name}
}