-
Notifications
You must be signed in to change notification settings - Fork 1
/
amiibo.go
60 lines (44 loc) · 1.12 KB
/
amiibo.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
package repository
import (
"context"
"github.com/bonaysoft/amiicli/internal/entity"
)
type AmiiboListOptions struct {
Name string
SearchPath string
}
func NewAmiiboListOptions(opts ...ListOption) *AmiiboListOptions {
options := new(AmiiboListOptions)
for _, opt := range opts {
opt.apply(options)
}
return options
}
type ListOption interface {
apply(*AmiiboListOptions)
}
type nameOption string
func (o nameOption) apply(opt *AmiiboListOptions) {
opt.Name = string(o)
}
func AmiiboListWithName(name string) ListOption {
return nameOption(name)
}
type searchDirOption string
func (o searchDirOption) apply(opt *AmiiboListOptions) {
opt.SearchPath = string(o)
}
func AmiiboListWithSearchDir(dir string) ListOption {
return searchDirOption(dir)
}
type AmiiboSearcher interface {
List(ctx context.Context, opts ...ListOption) ([]entity.Amiibo, error)
}
type AmiiboConstructor func() AmiiboSearcher
var supportAmiiboSearchers = map[string]AmiiboConstructor{
"remote": NewAmiiboRemote,
"local": NewAmiiboLocal,
}
func NewAmiiboSearcher(name string) AmiiboSearcher {
return supportAmiiboSearchers[name]()
}