-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstance.go
42 lines (34 loc) · 989 Bytes
/
instance.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
package luhner
//Generator interface defines the method signature to generate valid Luhm mod N strings
type Generator interface {
Generate() (string, error)
}
//Validator interface defines the method to validate generated strings
type Validator interface {
Validate(string) bool
}
//Instance interface defines a generator/validator pair
type Instance interface {
Generator
Validator
}
//NewInstance returns the default Instance implementation using DefaultConfig configured by Options
func NewInstance(opts ...Option) Instance {
c := NewDefaultConfig(opts...)
return NewInstanceWithConfig(c)
}
//NewInstanceWithConfig returns the default Instance implementation using the passed Config interface
func NewInstanceWithConfig(c Config) Instance {
return &instance{
c: c,
}
}
type instance struct {
c Config
}
func (i *instance) Generate() (string, error) {
return GenerateWithConfig(i.c)
}
func (i *instance) Validate(s string) bool {
return ValidateWithConfig(s, i.c)
}