forked from qri-io/starlib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
starlib.go
66 lines (61 loc) · 1.88 KB
/
starlib.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
61
62
63
64
65
66
package starlib
import (
"fmt"
"github.com/qri-io/starlib/bsoup"
"github.com/qri-io/starlib/compress/gzip"
"github.com/qri-io/starlib/dataframe"
"github.com/qri-io/starlib/encoding/base64"
"github.com/qri-io/starlib/encoding/csv"
"github.com/qri-io/starlib/encoding/json"
"github.com/qri-io/starlib/encoding/yaml"
"github.com/qri-io/starlib/geo"
"github.com/qri-io/starlib/hash"
"github.com/qri-io/starlib/html"
"github.com/qri-io/starlib/http"
"github.com/qri-io/starlib/math"
"github.com/qri-io/starlib/re"
"github.com/qri-io/starlib/time"
"github.com/qri-io/starlib/xlsx"
"github.com/qri-io/starlib/zipfile"
"go.starlark.net/starlark"
)
// Version is the current semver for the entire starlib library
const Version = "0.5.0"
// Loader presents the starlib library as a loader
func Loader(thread *starlark.Thread, module string) (dict starlark.StringDict, err error) {
switch module {
case time.ModuleName:
return starlark.StringDict{"time": time.Module}, nil
case gzip.ModuleName:
return starlark.StringDict{"gzip": gzip.Module}, nil
case http.ModuleName:
return http.LoadModule()
case xlsx.ModuleName:
return xlsx.LoadModule()
case html.ModuleName:
return html.LoadModule()
case bsoup.ModuleName:
return bsoup.LoadModule()
case zipfile.ModuleName:
return zipfile.LoadModule()
case re.ModuleName:
return re.LoadModule()
case base64.ModuleName:
return base64.LoadModule()
case csv.ModuleName:
return csv.LoadModule()
case json.ModuleName:
return starlark.StringDict{"json": json.Module}, nil
case yaml.ModuleName:
return yaml.LoadModule()
case geo.ModuleName:
return geo.LoadModule()
case math.ModuleName:
return starlark.StringDict{"math": math.Module}, nil
case hash.ModuleName:
return hash.LoadModule()
case dataframe.ModuleName:
return starlark.StringDict{"dataframe": dataframe.Module}, nil
}
return nil, fmt.Errorf("invalid module %q", module)
}