Load Google GO files as any javascript modules under nodeJS runtime.
npm install node-go-require      
> Load google go script as any javascript modules under nodeJS runtime.
* Overview
* Usage
* Installation
* Limitations
* API Documentation
* Contributing
* Release History
* License
See golang.org for more information.
``js`
require('node-go-require');
Now you can require your google go files like any other javascript files, for example:
`js
var petGo = require('./pet.go');
var pet = petGo.pet.New('my pet');
console.log(pet.Name());
pet.SetName('new name...');
console.log(pet.Name());
`
In your go file, instead of doing module.exports as in any JS file, use the gopherjs solution for exporting objects/functions.
Do not export to the global namespace, instead export to the module namespace.
For example:
`go`
js.Module.Get("exports").Set("pet", map[string]interface{}{
"New": New,
})
Full example (GO):
`go
package main
import "github.com/gopherjs/gopherjs/js"
type Pet struct {
name string
}
func New(name string) *js.Object {
return js.MakeWrapper(&Pet{name})
}
func (p *Pet) Name() string {
return p.name
}
func (p *Pet) SetName(name string) {
p.name = name
}
func main() {
js.Module.Get("exports").Set("pet", map[string]interface{}{
"New": New,
})
}
`
Full example (JavaScript):
`js
require('node-go-require');
var petGo = require('./pet.go');
var pet = petGo.pet.New('my pet');
console.log(pet.Name());
pet.SetName('new name...');
console.log(pet.Name());
`
In order to generate minified javascript code, first set the following environment variable:
`sh`
NODE_GO_REQUIRE_MINIFY=TRUE
`sh`
npm install --save node-go-require
Apart of installing the NPM modules, you will need to setup the following:
* Install Google Go - installation guide (make sure that GOPATH env variable is defined)
* Install gopherjs - gopherjs by running
`sh``
go get -u github.com/gopherjs/gopherjs
To see exact limitations please see gopherjs project at: gopherjs
| Date | Version | Description |
| ----------- | ------- | ----------- |
| 2020-05-12 | v2.0.0 | Migrate to github actions and upgrade minimal node version |
| 2019-02-08 | v1.1.5 | Maintenance |
| 2018-01-22 | v1.1.0 | Removed shelljs dependency and raised minimum node.js version to 0.12 |
| 2017-02-07 | v1.0.25 | Ability to generate minified js code |
| 2016-07-26 | v0.1.2 | Add integration test via docker |
| 2015-02-14 | v0.0.16 | Modified tests and examples due to changes in gopherjs API |
| 2015-02-09 | v0.0.15 | Grunt cleanups. |
| 2015-02-06 | v0.0.14 | Doc changes |
| 2015-02-05 | v0.0.13 | Fix continues integrations |
| 2015-02-05 | v0.0.12 | Minor internal quality changes |
| 2014-12-30 | v0.0.11 | Doc changes |
| 2014-12-07 | v0.0.10 | Minor internal changes |
| 2014-12-03 | v0.0.9 | No need to modify generated code |
| 2014-12-03 | v0.0.8 | Simplified code generation modification |
| 2014-12-02 | v0.0.7 | Mock gopherjs calls for continues integration tests. |
| 2014-12-02 | v0.0.3 | Initial release. |