🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis
Socket
Book a DemoInstallSign in
Socket

node-go-require

Package Overview
Dependencies
Maintainers
1
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-go-require

Load Google GO files as any javascript modules under nodeJS runtime.

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

node-go-require

NPM Version CI Coverage Status Known Vulnerabilities Inline docs License Total Downloads

Load google go script as any javascript modules under nodeJS runtime.

Overview

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

See golang.org for more information.

Usage

In order to use google go scripts under node, you need to first require this library as follows

require('node-go-require');

Now you can require your google go files like any other javascript files, for example:

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:

js.Module.Get("exports").Set("pet", map[string]interface{}{
    "New": New,
})

Full example (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):

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:

NODE_GO_REQUIRE_MINIFY=TRUE

Installation

In order to use this library, just run the following npm install command:

npm install --save node-go-require

Apart of installing the NPM modules, you will need to setup the following:

go get -u github.com/gopherjs/gopherjs

Limitations

The Google Go to javascript conversion is done by gopherjs and there are some limitations of running the gopherjs generated code under node runtime.

To see exact limitations please see gopherjs project at: gopherjs

API Documentation

See full docs at: API Docs

Contributing

See contributing guide

Release History

DateVersionDescription
2020-05-12v2.0.0Migrate to github actions and upgrade minimal node version
2019-02-08v1.1.5Maintenance
2018-01-22v1.1.0Removed shelljs dependency and raised minimum node.js version to 0.12
2017-02-07v1.0.25Ability to generate minified js code
2016-07-26v0.1.2Add integration test via docker
2015-02-14v0.0.16Modified tests and examples due to changes in gopherjs API
2015-02-09v0.0.15Grunt cleanups.
2015-02-06v0.0.14Doc changes
2015-02-05v0.0.13Fix continues integrations
2015-02-05v0.0.12Minor internal quality changes
2014-12-30v0.0.11Doc changes
2014-12-07v0.0.10Minor internal changes
2014-12-03v0.0.9No need to modify generated code
2014-12-03v0.0.8Simplified code generation modification
2014-12-02v0.0.7Mock gopherjs calls for continues integration tests.
2014-12-02v0.0.3Initial release.

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

Keywords

go

FAQs

Package last updated on 12 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts