Documentation
¶
Overview ¶
Package gopherjslib provides helpers for in-process GopherJS compilation.
All of them take the optional *Options argument. It can be used to set a different GOROOT or GOPATH directory or to enable minification.
Example compiling Go code:
import "github.com/shurcooL/gopherjslib" ... code := strings.NewReader(` package main import "github.com/gopherjs/gopherjs/js" func main() { println(js.Global.Get("window")) } `) var out bytes.Buffer err := gopherjslib.Build(code, &out, nil) // <- default options
Example compiling multiple files:
var out bytes.Buffer builder := gopherjslib.NewBuilder(&out, nil) fileA := strings.NewReader(` package main import "github.com/gopherjs/gopherjs/js" func a() { println(js.Global.Get("window")) } `) builder.Add("a.go", fileA) // And so on for each file, then: err = builder.Build()
Deprecated: The intermediate API layer implemented by this package has proven to be unhelpful and is now unmaintained. Use packages github.com/gopherjs/gopherjs/build and github.com/gopherjs/gopherjs/compiler or command github.com/gopherjs/gopherjs directly instead.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build builds JavaScript based on the go code in reader, writing the result to target. The first error during the built is returned. All errors are typed.
reader must not be nil target must not be nil options may be nil (defaults)
func BuildPackage ¶
BuildPackage builds JavaScript based on the go package in dir, writing the result to target. Note that dir is not relative to any GOPATH, but relative to the working directory. The first error during the built is returned. dir must be an existing directory containing at least one go file
target must not be nil options may be nil (defaults)
Types ¶
type Builder ¶
type Builder interface { // Add adds the content of reader for the given filename Add(filename string, reader io.Reader) Builder // Build builds and returns the first error during the built or <nil> Build() error }
Builder builds from added files
func NewBuilder ¶
NewBuilder creates a new Builder that will write to target.
target must not be nil options may be nil (defaults)
type ErrorCompiling ¶
type ErrorCompiling string
ErrorCompiling is the error that is returned if compilation fails
func (ErrorCompiling) Error ¶
func (e ErrorCompiling) Error() string
type ErrorImportingDependencies ¶
type ErrorImportingDependencies string
ErrorImportingDependencies is the error that is returned if dependency import fails
func (ErrorImportingDependencies) Error ¶
func (e ErrorImportingDependencies) Error() string
type ErrorMissingTarget ¶
type ErrorMissingTarget struct{}
ErrorMissingTarget is the error that is returned, if the target is <nil>
func (ErrorMissingTarget) Error ¶
func (e ErrorMissingTarget) Error() string
type ErrorParsing ¶
type ErrorParsing struct {
FileName, Message string
}
ErrorParsing is the error that is returned, if there is an error when parsing file FileName
func (ErrorParsing) Error ¶
func (e ErrorParsing) Error() string