Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ngo

doesdev1.4kMIT2.7.0

Run Go commands from Node or CLI, Go env not required

go, golang, environment, env, cli, interop, run, command

readme

ngo NPM version js-standard-style Dependency Status Build status Build Status

Run Go commands from Node or CLI, Go env not required

Will download latest binaries locally if Go isn't already in PATH

BONUS

If you run a command and it fails with "cannot find package..." we'll try to install said package(s). YAYS. :relieved:

local install

$ npm install --save ngo

cli install

$ npm install --global ngo

usage

cli usage

$ ngo version
# go version go1.8.3 windows/amd64

# to update the `ngo` install of Go (won't update system version)
$ ngo-update
# go version go1.9.4 windows/amd64

# to set the `ngo` install of Go to a specific version (won't update system version)
$ ngo-version 1.12.0
# go version go1.12.0 windows/amd64

# to run a `go get` installed binary use this bs
$ ngo-binary golint test/fixtures/errors.go
# test\fixtures\errors.go:13:5: error var unexp should have name of the form errFoo

programmatic usage

returns promise that resolves to execa style object without the child_process goodies

const goOpts = {}
const ngo = require('ngo')(goOpts)
const golint = ngo.bin('golint')

ngo('version').then(console.log).catch(console.error)
/* {
 stdout: 'go version go1.8.3 windows/amd64',
 stderr: '',
 code: 0,
 failed: false,
 killed: false,
 signal: null,
 cmd: 'C:\\Go\\bin\\go version'
} */

golint('main.go').then(console.log).catch(console.error)

api

const ngo = require('ngo')(options)

  • Purpose: initialize ngo
  • Arguments:
    • options [Object - optional]
      • useLocal [Boolean false] - use locally downloaded Go binaries)
      • update [Boolean false] - update local install to latest
      • installDeps [Boolean true] - attempt to install missing packages
      • env [Object] - environment vars to set for the Go command
      • goRoot [String] - Go root path (ex. /usr/local/go)
      • goPath [String] - Go workspace path (ex. ~/work)
  • Returns: Function (ngo) which executes Go commands

ngo(commandArgs, options)

  • Purpose: - execute go commands
  • Arguments:
    • commandArgs [Array | String - required] - argument(s) to call with go command
    • options [Object - optional]
  • Returns: Promise which resolves to execa styled object

ngo.bin(binary)

  • Purpose: - execute commands on binaries in the GOBIN directory
  • Arguments:
    • binary [String] - name of binary file to be executed in returned function
  • Returns: Function (identical to ngo, but runs specified binary instead of go)

ngo.env

this is a copy of ngo's process.env with the Go environment variables added to it

License

MIT © Andrew Carpenter

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

2.7.0

21 June 2021

  • Add ngo-version command
  • Update dependencies

2.6.2

15 April 2020

  • Update dependencies

2.6.1

14 July 2019

  • Update dependencies
  • Use mvt for tests

2.6.0

8 June 2019

  • Update deps, CI node targets

2.5.2

9 October 2018

2.5.1

9 October 2018

2.5.0

10 August 2018

  • Update deps, fixes version numbers in wrong order 1e3d944

2.4.9

15 April 2018

  • If no args passed default to help ab57778

2.4.8

15 April 2018

  • Ensure default GOBIN is relative to GOPATH 699fce9

2.4.7

15 April 2018

  • Don't test against locked deps in CI 3fedde0
  • Don't include garbage from go path in tarball 0763a07
  • Update changelog bb272ae

2.4.6

14 April 2018

  • Add ngo-binary command line 7087f99
  • Add ngo.bin, tweak readme a bit 80fdf88
  • Update lockfile to fix travis d9dc8f8

2.4.5

21 March 2018

  • Update deps and use gh token var in appveyor 3da334d
  • Release with updated deps and cpu arch fix 7fc4630
  • Don't start installing go in test until clean d1552fc

2.4.4

18 March 2018

2.4.3

18 March 2018

2.4.2

18 March 2018

2.4.1

18 March 2018

2.4.0

18 March 2018

2.3.3

17 March 2018

  • Hopefully the last tweak on installDeps error 947a080

2.3.2

17 March 2018

  • Reject, not resolve that last guy e202723

2.3.1

17 March 2018

  • Tweak error handling in installDeps c52cddd

2.3.0

17 March 2018

  • Make it mo awesome, install missing pkgs 78fa227

2.2.1

16 March 2018

2.2.0

16 March 2018

  • Add update command / option 0cdc2e1

2.1.1

16 March 2018

2.1.0

28 January 2018

v2.0.0

29 May 2017

  • Update readme to reflect v2.0.0 API 89199c9
  • Update execa, ensure opts are passed correctly 4db70e9
  • Simplify API a bit 573025d