-
Notifications
You must be signed in to change notification settings - Fork 1
/
kernel.go
40 lines (36 loc) · 924 Bytes
/
kernel.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
package MagicCapKernel
import (
"encoding/json"
MagicCapKernelStandards "github.com/magiccap/magiccap-uploaders-kernel/standards"
)
// Kernel defines the kernel structure.
type Kernel struct {
Uploaders map[string]*MagicCapKernelStandards.Uploader
}
// Load loads a map of uploaders from V1.
func (k Kernel) Load(V1File map[string]interface{}) error {
StandardsMap := MagicCapKernelStandards.GetStandardsMap()
for Implementation, UploaderMap := range V1File {
Loader := StandardsMap[Implementation]
if Loader == nil {
continue
}
for key, v := range UploaderMap.(map[string]interface{}) {
b, err := json.Marshal(v)
if err != nil {
return err
}
var std MagicCapKernelStandards.UploaderStructure
err = json.Unmarshal(b, &std)
if err != nil {
return err
}
uploader, err := Loader(std)
if err != nil {
return err
}
k.Uploaders[key] = uploader
}
}
return nil
}