-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.go
60 lines (50 loc) · 1.39 KB
/
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
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
// Copyright 2016 Giulio Iotti. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package kuradns
import (
"fmt"
"github.com/dullgiulio/kuradns/cfg"
"github.com/dullgiulio/kuradns/gen"
)
// sources is the collection of source objects keyed by name.
type sources map[string]*source
// source is the generator of DNS entries with its configuration and name.
type source struct {
name string
err error
conf *cfg.Config
gen gen.Generator
}
// makeSources allocates a sources collection.
func makeSources() sources {
return make(map[string]*source)
}
// has returns true if the sources collection contains a source named k.
func (s sources) has(k string) bool {
_, ok := s[k]
return ok
}
// newSource allocates a source.
func newSource(name string, conf *cfg.Config) *source {
return &source{
name: name,
conf: conf,
}
}
// initGenerator initializes the generator for a new production of key/values.
func (s *source) initGenerator() error {
stype, ok := s.conf.Get("source.type")
if !ok {
return fmt.Errorf("cannot start generator %s: key source.type not found", s.name)
}
s.gen, s.err = gen.MakeGenerator(stype, s.conf)
if s.err != nil {
return fmt.Errorf("cannot start generator: %s", s.err)
}
return nil
}
// String representation of a source is its name.
func (s *source) String() string {
return s.name
}