forked from muesli/beehive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
66 lines (57 loc) · 1.79 KB
/
config.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (C) 2014-2017 Christian Muehlhaeuser
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Christian Muehlhaeuser <[email protected]>
*/
// Package bees is Beehive's central module system.
package bees
import "errors"
// BeeConfig contains all settings for a single Bee.
type BeeConfig struct {
Name string
Class string
Description string
Options BeeOptions
}
// NewBeeConfig validates a configuration and sets up a new BeeConfig
func NewBeeConfig(name, class, description string, options BeeOptions) (BeeConfig, error) {
if len(name) == 0 {
return BeeConfig{}, errors.New("A Bee's name can't be empty")
}
b := GetBee(name)
if b != nil {
return BeeConfig{}, errors.New("A Bee with that name already exists")
}
f := GetFactory(class)
if f == nil {
return BeeConfig{}, errors.New("Invalid class specified")
}
return BeeConfig{
Name: name,
Class: class,
Description: description,
Options: options,
}, nil
}
// BeeConfigs returns configs for all Bees.
func BeeConfigs() []BeeConfig {
bs := []BeeConfig{}
for _, b := range bees {
bs = append(bs, (*b).Config())
}
return bs
}