-
Notifications
You must be signed in to change notification settings - Fork 137
/
prefixer.go
50 lines (40 loc) · 1.29 KB
/
prefixer.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
package prefixer
// Prefixer interface describes a handle for a specific instance by its domain
// and a specific and unique prefix.
type Prefixer interface {
DBCluster() int
DBPrefix() string
DomainName() string
}
type prefixer struct {
cluster int
domain string
prefix string
}
// UnknownDomainName represents the human-readable string of an empty domain
// name of a prefixer struct
const UnknownDomainName string = "<unknown>"
func (p *prefixer) DBCluster() int { return p.cluster }
func (p *prefixer) DBPrefix() string { return p.prefix }
func (p *prefixer) DomainName() string {
if p.domain == "" {
return UnknownDomainName
}
return p.domain
}
// NewPrefixer returns a prefixer with the specified domain and prefix values.
func NewPrefixer(cluster int, domain, prefix string) Prefixer {
return &prefixer{
cluster: cluster,
domain: domain,
prefix: prefix,
}
}
// GlobalCouchCluster is the index of the CouchDB cluster for the global and
// secrets databases.
const GlobalCouchCluster = -1
// GlobalPrefixer returns a global prefixer with the wildcard '*' as prefix.
var GlobalPrefixer = NewPrefixer(GlobalCouchCluster, "", "global")
// SecretsPrefixer is the the prefix used for db which hold
// a cozy stack secrets.
var SecretsPrefixer = NewPrefixer(GlobalCouchCluster, "", "secrets")