-
Notifications
You must be signed in to change notification settings - Fork 0
/
ineed.go
49 lines (40 loc) · 791 Bytes
/
ineed.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
package i
import (
"github.com/oleiade/reflections"
"github.com/pborman/uuid"
)
type (
want map[string]interface{}
Need interface {
MapInto(interface{})
Get(string) interface{}
CastInto(interface{})
}
)
func (s want) Get(name string) interface{} {
return s[name]
}
func (s want) ToMap(n string, d interface{}) want {
s[n] = d
return s
}
func (s want) ToUse(d interface{}) want {
s.ToMap(uuid.New(), d)
return s
}
func (s want) CastInto(obj interface{}) {
fields, _ := reflections.Fields(obj)
for _, fieldname := range fields {
for _, dependency := range s {
reflections.SetField(obj, fieldname, dependency)
}
}
}
func (s want) MapInto(obj interface{}) {
for n, v := range s {
reflections.SetField(obj, n, v)
}
}
func Want() want {
return make(want)
}