-
Notifications
You must be signed in to change notification settings - Fork 0
/
maester.go
69 lines (57 loc) · 1.46 KB
/
maester.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
67
68
69
// Copyright © 2016 Jason Smith <[email protected]>.
//
// Use of this source code is governed by the LGPL-3
// license that can be found in the LICENSE file.
package maester
import (
"flag"
"fmt"
"os"
"github.com/duckbunny/service"
)
// MaesterTypes are a collection of maester interface identified by strings
// associated with a maester type
var MaesterTypes map[string]Maester = make(map[string]Maester)
// Flags to be parsed for setting pool and declaration interfaces.
var maester string
var coreMaester Maester
func init() {
flag.StringVar(&maester, "maester", os.Getenv("MAESTER"), "Maester to load config values.")
}
type Maester interface {
Set(string) ([]byte, error)
Get(string) ([]byte, error)
Init(*service.Service) error
}
func Init() error {
if !flag.Parsed() {
flag.Parse()
}
if maester != "" {
if _, ok := MaesterTypes[maester]; !ok {
err := fmt.Errorf(
"Attempt to utilize unrecognized Maester mechanism %v", maester)
return err
}
coreMaester = MaesterTypes[maester]
}
s, err := service.This()
if err != nil {
return err
}
return coreMaester.Init(s)
}
// Get a foreign microservice definition.
func Get(s string) ([]byte, error) {
return coreMaester.Get(s)
}
// AddMaester adds a Maester type.
func AddMaester(key string, m Maester) {
MaesterTypes[key] = m
}
// AddMaesters adds Multiple Maesters at once.
func AddMaesters(ms map[string]Maester) {
for key, maester := range ms {
MaesterTypes[key] = maester
}
}