Documentation
¶
Index ¶
- Constants
- func Module(path string) []byte
- func Parse(input []byte, format __std.Format) ([]byte, error)
- func Unparse(jsonString []byte, format __std.Format) ([]byte, error)
- type Directory
- type FileInfo
- type ModuleAccess
- type ModuleAccesser
- type ModuleResources
- type Options
- type Params
- func (p Params) Get(path string) (interface{}, error)
- func (p Params) GetBool(path string) (bool, error)
- func (p Params) GetNumber(path string) (float64, error)
- func (p Params) GetObject(path string) (Params, error)
- func (p Params) GetString(path string) (string, error)
- func (p Params) Merge(a Params)
- func (p Params) Set(path string, v interface{})
- func (p Params) SetBool(path string, b bool)
- func (p Params) SetNumber(path string, f float64)
- func (p Params) SetObject(path string, o Params)
- func (p Params) SetString(path string, s string)
- func (p Params) String() string
- type RPCFunc
- type Sandbox
- type Std
Constants ¶
const NativeEndian = unicode.LittleEndian
NativeEndian is the platform-specific endianness. We need this because certain things in JS, e.g., Uint16Array, use "native endianness".
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Directory ¶
type Directory struct { Name string `json:"name"` Path string `json:"path"` Files []FileInfo `json:"files"` }
Directory is the result from an std.dir RPC
type FileInfo ¶
type FileInfo struct { Name string `json:"name"` Path string `json:"path"` IsDir bool `json:"isdir"` }
FileInfo is the result from a std.fileinfo RPC (and used to represent each file, within Directory)
type ModuleAccess ¶
type ModuleAccess struct { // Does this module allow paths outside the sandbox? AllowPathsOutsideSandbox bool // The location within a virtual filesystem; usually, but not // necessarily, the root of the virtual filesystem. Loc vfs.Location // Writes don't go through a virtual filesystem. This flag means // "allow writes to the host filesystem with this module". AllowWriteToHost bool }
ModuleAccess represents access to a module's resources
type ModuleAccesser ¶
type ModuleAccesser interface {
GetModuleAccess(string) (ModuleAccess, bool)
}
ModuleAccesser is an interface for getting the module back from a token
type ModuleResources ¶
type ModuleResources struct {
// contains filtered or unexported fields
}
ModuleResources keeps track of the base paths for modules, as well as generating the magic modules when they are imported.
func NewModuleResources ¶
func NewModuleResources() *ModuleResources
NewModuleResources initialises a new ModuleResources
func (*ModuleResources) GetModuleAccess ¶
func (r *ModuleResources) GetModuleAccess(token string) (ModuleAccess, bool)
GetModuleAccess looks up a module given a token.
func (*ModuleResources) MakeResourceModule ¶
func (r *ModuleResources) MakeResourceModule(mod ModuleAccess) ([]byte, string)
MakeResourceModule generates resource module code (and path) given the importing module's base path.
type Options ¶
type Options struct { // Verbose indicates if some operations, such as write, should print out what // they are doing. Verbose bool // Parameters is a structured set of input parameters. Parameters Params // Sandbox mediates reads and writes to the filesystem Sandbox Sandbox // DryRun instructs standard library functions to not complete operations that // would mutate something (eg. std.write()). DryRun bool // ExtMethods is where extension RPC methods are registered (the // standard ones are here, and take precedence) ExtMethods map[string]RPCFunc }
Options are global configuration options to tweak the behavior of the standard library.
type Params ¶
type Params map[string]interface{}
Params is a paramater store akin to a JSON object.
func NewParamsFromFile ¶
NewParamsFromFile creates Params from a JSON or YAML file.
func NewParamsFromJSON ¶
NewParamsFromJSON creates Params from a JSON object.
func NewParamsFromYAML ¶
NewParamsFromYAML creates Params from a YAML object.
type RPCFunc ¶
type RPCFunc func([]interface{}) (interface{}, error)
RPCFunc is a function that can be registered for dispatch. The arguments each will either be []byte or JSON values; any result returned will be serialised to JSON.
type Sandbox ¶
type Sandbox struct { // The location in a virtual filesystem that is the top-most that // can be read from Base vfs.Location // The top-most directory that can be written to WriteRoot string // Look-up for resources (i.e., for module-relative reads) Modules ModuleAccesser // For recording each read or write Recorder *record.Recorder }
Sandbox mediates access to the filesystem by resolving relative paths to the host filesystem and resources (module-relative paths). Reads outside the base are forbidden and will return an error.