1
2
3
4
5
6
7 package impl
8
9 type implementation struct {
10 Package string
11 Name string
12 Available bool
13 Toggle *bool
14 }
15
16 var allImplementations []implementation
17
18
19
20
21
22
23
24
25
26
27 func Register(pkg, name string, available *bool) {
28 allImplementations = append(allImplementations, implementation{
29 Package: pkg,
30 Name: name,
31 Available: *available,
32 Toggle: available,
33 })
34 }
35
36
37
38
39 func List(pkg string) []string {
40 var names []string
41 for _, i := range allImplementations {
42 if i.Package == pkg {
43 names = append(names, i.Name)
44 }
45 }
46 return names
47 }
48
49 func available(pkg, name string) bool {
50 for _, i := range allImplementations {
51 if i.Package == pkg && i.Name == name {
52 return i.Available
53 }
54 }
55 panic("unknown implementation")
56 }
57
58
59
60
61 func Select(pkg, name string) bool {
62 if name == "" {
63 for _, i := range allImplementations {
64 if i.Package == pkg {
65 *i.Toggle = false
66 }
67 }
68 return true
69 }
70 if !available(pkg, name) {
71 return false
72 }
73 for _, i := range allImplementations {
74 if i.Package == pkg {
75 *i.Toggle = i.Name == name
76 }
77 }
78 return true
79 }
80
81 func Reset(pkg string) {
82 for _, i := range allImplementations {
83 if i.Package == pkg {
84 *i.Toggle = i.Available
85 return
86 }
87 }
88 }
89
View as plain text