GithubHelp home page GithubHelp logo

alexxnica / node-go-require Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sagiegurari/node-go-require

0.0 1.0 0.0 194 KB

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

License: Apache License 2.0

JavaScript 87.46% Shell 2.79% Go 9.75%

node-go-require's Introduction

node-go-require

NPM Version Build Status Coverage Status bitHound Code Inline docs
License Total Downloads Dependency Status devDependency Status
Known Vulnerabilities Retire Status

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
2017-11-06 v1.0.45 Maintenance
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.

node-go-require's People

Contributors

sagiegurari avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.