-
Notifications
You must be signed in to change notification settings - Fork 1
/
gomobile_exports.go
60 lines (52 loc) · 1.36 KB
/
gomobile_exports.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
// +build ios android
package MagicCapKernel
import "C"
import (
"encoding/json"
MagicCapKernelStandards "github.com/magiccap/magiccap-uploaders-kernel/standards"
)
var cKernel *Kernel
// InitKernel is used to initialise a local variable with a kernel with the bytes specified.
//export InitKernel
func InitKernel(Data []byte) error {
var x map[string]interface{}
err := json.Unmarshal(Data, &x)
if err != nil {
return err
}
k := Kernel{Uploaders: map[string]*MagicCapKernelStandards.Uploader{}}
err = k.Load(x)
if err != nil {
return err
}
cKernel = &k
return nil
}
// GetUploaderIDs is used to get a byte array containing a JSON array of the ID's of uploaders.
//export GetUploaderIDs
func GetUploaderIDs() []byte {
x := make([]string, len(cKernel.Uploaders))
i := 0
for k := range cKernel.Uploaders {
x[i] = k
i++
}
b, _ := json.Marshal(x)
return b
}
// GetUploader is used to get bytes which is a JSON object of the uploader by ID.
//export GetUploader
func GetUploader(ID string) []byte {
b, _ := json.Marshal(cKernel.Uploaders[ID])
return b
}
// UploadFile is used to upload a file.
//export UploadFile
func UploadFile(UploaderID, Filename string, Data, Config []byte) (string, error) {
var x map[string]interface{}
err := json.Unmarshal(Config, &x)
if err != nil {
return "", err
}
return cKernel.Uploaders[UploaderID].Upload(x, Data, Filename)
}