Skip to content

pkg/plugin: implement using es6 module imports #842

Open
@paralin

Description

@paralin

The plugin package in Go declares a simple mechanism for loading Go plugins.

  • A package is compiled with the command go build -buildmode=plugin
  • A plugin file is produced (on Linux this is a shared library)
  • At runtime, a program can load a plugin and all exported symbols.
// Open opens a Go plugin.
// If a path has already been opened, then the existing *Plugin is returned.
// It is safe for concurrent use by multiple goroutines.
func Open(path string) (*Plugin, error) {
	// GopherJS: load the plugin from the .js file using module.exports.
}

// Lookup searches for a symbol named symName in plugin p.
// A symbol is any exported variable or function.
// It reports an error if the symbol is not found.
// It is safe for concurrent use by multiple goroutines.
func (p *Plugin) Lookup(symName string) (Symbol, error) {
	// GopherJS: lookup the symbol using the lookup table.
}

Docs: https://golang.org/pkg/plugin/

There are then two components that could be implemented for GopherJS:

  • Compiler: build mode to produce plugin (module.exports exported symbol table)
  • Runtime: implement plugin package with proper init() ordering at open() time

Would this be feasible to implement in GopherJS?

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions