generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathregistry.go
43 lines (35 loc) · 889 Bytes
/
registry.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
package ferrite
import (
"github.com/dogmatiq/ferrite/internal/variable"
)
// A Registry is a collection of environment variable specifications.
type Registry interface {
variable.ProtectedRegistry
}
// RegistryOption is an option that configures the behavior of a registry.
type RegistryOption interface {
applyRegistryOption(*variable.Registry)
}
// NewRegistry returns a new environment variable registry.
//
// Use the [WithRegistry] option to configure an environment variable definition
// or [Init] call to use a specific registry.
func NewRegistry(
key, name string,
options ...RegistryOption,
) Registry {
if key == "" {
panic("registry key must not be empty")
}
if name == "" {
panic("registry name must not be empty")
}
reg := &variable.Registry{
Key: key,
Name: name,
}
for _, opt := range options {
opt.applyRegistryOption(reg)
}
return reg
}