gopherjslib: github.com/shurcooL/gopherjslib Index | Files

package gopherjslib

import "github.com/shurcooL/gopherjslib"

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()

Index

Package Files

error.go gopherjslib.go

func Build Uses

func Build(reader io.Reader, target io.Writer, options *Options) error

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 Uses

func BuildPackage(dir string, target io.Writer, options *Options) error

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)

type Builder Uses

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 Uses

func NewBuilder(target io.Writer, options *Options) Builder

NewBuilder creates a new Builder that will write to target.

target must not be nil
options may be nil (defaults)

func NewPackageBuilder Uses

func NewPackageBuilder(dir string, target io.Writer, options *Options) (Builder, error)

NewPackageBuilder creates a new Builder based on the go package in dir.

type ErrorCompiling Uses

type ErrorCompiling string

ErrorCompiling is the error that is returned if compilation fails

func (ErrorCompiling) Error Uses

func (e ErrorCompiling) Error() string

type ErrorImportingDependencies Uses

type ErrorImportingDependencies string

ErrorImportingDependencies is the error that is returned if dependency import fails

func (ErrorImportingDependencies) Error Uses

func (e ErrorImportingDependencies) Error() string

type ErrorMissingTarget Uses

type ErrorMissingTarget struct{}

ErrorMissingTarget is the error that is returned, if the target is <nil>

func (ErrorMissingTarget) Error Uses

func (e ErrorMissingTarget) Error() string

type ErrorParsing Uses

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 Uses

func (e ErrorParsing) Error() string

type Options Uses

type Options struct {
    GOROOT string // defaults to build.Default.GOROOT
    GOPATH string // defaults to build.Default.GOPATH
    Minify bool   // should the js be minified
}

Options is the subset of build.Options, that is exposed to the user of gopherjslib and is optional.

Package gopherjslib imports 10 packages (graph) and is imported by 3 packages. Updated 2016-09-19. Refresh now. Tools for package owners.