Documentation ¶
Overview ¶
Package module implements a Node.js-like modular system for Go/Otto
Bind this module to the Otto runtime and then within JavaScript a require stanza can be used.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FileLoader ¶
type FileLoader interface { // Load loads a file. // // If the file is not found, this returns os.ErrNotExist. Other errors // are possible for other read failures. Load(filename string) ([]byte, error) IsFile(filename string) bool IsDir(filename string) bool }
FileLoader describes something able to load a file by name.
This returns the data as a []byte, and an error under any condition in which the file cannot be completely read.
It should not be assumed that the file returned from a loader can be found on the filesystem.
func DefaultLoader ¶
func DefaultLoader(path string) FileLoader
DefaultLoader creates a strategic loader backed by a filesystem loader.
This is suitable for loading off of a local filesystem.
type FilesystemLoader ¶
type FilesystemLoader string
FilesystemLoader is a simple filesystem-based FileLoader
Functions here will evaluate path. If the path is absolute, the path is evaluated as-is. If the path is relative, it is joined with the parent path.
func (FilesystemLoader) IsDir ¶
func (f FilesystemLoader) IsDir(path string) bool
func (FilesystemLoader) IsFile ¶
func (f FilesystemLoader) IsFile(path string) bool
func (FilesystemLoader) String ¶
func (f FilesystemLoader) String() string
type Module ¶
type Module struct { Require func(string) otto.Value `otto:"require"` Children []otto.Value `otto:"children"` Exports otto.Value `otto:"exports"` Filename string `otto:"filename"` Id string `otto:"id"` Loaded bool `otto:"loaded"` Parent otto.Value `otto:"parent"` }
Module describes a JavaScript module.
The structure is based off of Node.js's module function, but compatibility is not ensured. https://nodejs.org/api/modules.html
type StrategicLoader ¶
type StrategicLoader struct {
// contains filtered or unexported fields
}
StrategicLoader implements the different load strategies (directory, file, etc.)
This can be wrapped around a basic loader, and it will use internal strategies to load files according to the Module interface for Node.js.
func NewStrategicLoader ¶
func NewStrategicLoader(loader FileLoader) *StrategicLoader
func (*StrategicLoader) IsDir ¶
func (s *StrategicLoader) IsDir(name string) bool
func (*StrategicLoader) IsFile ¶
func (s *StrategicLoader) IsFile(name string) bool