• Stars
    star
    154
  • Rank 242,095 (Top 5 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created almost 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

Date Version Description
2020-05-13 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.

License

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

More Repositories

1

cargo-make

Rust task runner and build tool.
Rust
2,520
star
2

duckscript

Simple, extendable and embeddable scripting language.
Rust
506
star
3

angular-web-notification

Web Notifications AngularJS Service
JavaScript
175
star
4

brackets-portable

Windows portable version of adobe brackets web development editor.
HTML
130
star
5

run_script

Run shell scripts in rust.
Rust
120
star
6

simple-web-notification

Web Notifications made easy
JavaScript
75
star
7

shell2batch

Coverts simple basic shell scripts to windows batch scripts.
Rust
56
star
8

simple-oracledb

Extend capabilities of oracledb with simplified API for quicker development.
JavaScript
36
star
9

envmnt

Environment variables utility functions.
Rust
27
star
10

simple_redis

Simple and resilient redis client for rust.
Rust
25
star
11

fax4j

Java fax library.
Java
23
star
12

ci_info

Provides current CI environment information.
Rust
14
star
13

userscripts-ads-dom-remover

Removes Ad Containers from DOM (doesn't replace adblocker extension, but blocks dynamic content which the adblocker fails to block by removing whole sections from the HTML DOM.)
JavaScript
14
star
14

multiple-redis

Run redis commands against multiple redis instances.
JavaScript
13
star
15

event-emitter-enhancer

Extends the Node.js events.EventEmitter to provide additional functionality.
JavaScript
11
star
16

rust_info

Extracts the current rust compiler information.
Rust
8
star
17

fsio

File System and Path utility functions.
Rust
8
star
18

cargo-make-tasks

Reusable makefiles for cargo-make
8
star
19

cliparser

Simple command line parser
Rust
8
star
20

grunt-markdownlint

A grunt task for markdown style checker and lint tool.
JavaScript
7
star
21

c_stringfn

String functions for C.
C
7
star
22

node-spider-script

Run spider script files as javascript modules in NodeJS.
JavaScript
6
star
23

git_info

Extracts git repository information.
Rust
6
star
24

c_forever

Ensure the program runs continuously.
C
5
star
25

c_workqueue

Threaded work queue for C.
C
5
star
26

c_string_buffer

A simple string buffer for C
C
5
star
27

c_scriptexec

Invoke complex multi command scripts with a single C api call.
C
4
star
28

x2fax

The x2fax (fax4j sub project) is a set of standalone servers and deployable components which enable to provide x2fax capabilities.
Java
4
star
29

c_hs

Embeddable HTTP Server for C
C
4
star
30

c_ini

INI parser/writer for C
C
3
star
31

scriptexec

Run complex native scripts with a single command, similar to system commands.
R
3
star
32

oracledb-upsert

UPSERT (insert/update) extension to oracledb
JavaScript
3
star
33

angular-number-input

AngularJS number input directive.
JavaScript
3
star
34

c_json

JSON parser/writer for C
C
3
star
35

c_hashtable

C Hash TAble
C
2
star
36

c_vector

A simple growable vector for C
C
2
star
37

sagiegurari.github.io

https://sagiegurari.github.io
HTML
2
star
38

c_thread_pool

Thread Pool for C
C
2
star
39

cmake-modules

Reusable cmake utilities for C projects.
CMake
2
star
40

userscripts-hackernews

Improved mobile usability and modern styling for Hackernews
JavaScript
2
star
41

c_eventemitter

Simple Event Emitter C API
C
2
star
42

c_fsio

File System utility functions.
C
2
star
43

c_thread_lock

Simple Thread Lock/Signal for C
C
2
star
44

funcs-js

Function wrappers for enhanced behavior.
JavaScript
2
star
45

node-later

Defer function calls to the start of the next cycle.
JavaScript
2
star
46

misc-test

misc tests
1
star
47

js-project-commons

Common web and node.js grunt tasks/lint configs/md templates and so on...
JavaScript
1
star
48

docker-cargo-make

Docker image with Rust and cargo-make preinstalled.
Dockerfile
1
star