Documentation
¶
Overview ¶
Package gojsonata provides utility functions to execute JSONata expression for JSON data transformations
Index ¶
- func AddModuleFile(filename string) error
- func AddModuleSource(key, source string) error
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func CachedModules() []string
- func CallScript(source, result string) (otto.Value, error)
- func CallScriptFile(filename, result string) (otto.Value, error)
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func RunScript(source interface{}) (otto.Value, error)
- func Transform(data interface{}, expr string) (interface{}, error)
- type Engine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddModuleFile ¶
AddModuleFile loads content of a js module file and add the result to cache, so later script evaluation can use this module
func AddModuleSource ¶
AddModuleSource loads source code of a js module file and add the result to cache, so later script evaluation can use this module
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func CachedModules ¶
func CachedModules() []string
CachedModules returns names of js modules currently loaded in the engine
func CallScript ¶
CallScript evaluates a js script, and return value of specified result var It checks if all required modules are loaded in cache
func CallScriptFile ¶
CallScriptFile evaluates content of js or json file, and return value of specified result var the file extension must be .js or .json
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type Engine ¶
Engine is modular vm environment
func (*Engine) LoadModule ¶
LoadModule loads source code of a js module. It recursively loads dependent modules required by the source code. All dependent modules' source code should be preloaded in jsdata.go, or loaded before this module. Note: this implementation is based on https://github.com/ddliu/motto/blob/master/module.go
func (*Engine) Require ¶
Require implements js 'require(name)' for modeules. It first check if the module is already in cache, then check if it is a preloaded resource in jsdata.go. It returns error if source code of the specified module is not found. Note: input name may contains file path info, e.g., ./js/mycode.js, but the cache key will use only the file name without suffix, i.e., mycode => value