Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nx-go/nx-go

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nx-go/nx-go

nx-go Nx plugin to use Go in a Nx workspace.

  • 2.0.0-beta.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20K
increased by0.25%
Maintainers
1
Weekly downloads
 
Created
Source

nx-go

Nx plugin to use Go in a Nx workspace.

nx-go logo

Getting started

First, make sure you have a Nx Workspace.

Create a new one using the following command:

yarn create nx-workspace go-playground --preset=empty --cli=nx --nx-cloud true
cd go-playground

Next, install the nx-go plugin:

yarn add -D @nx-go/nx-go

Create a new application:

nx g @nx-go/nx-go:app api

Usage

You can now run the Nx workspace commands:

Building the application

This command builds the application using the go build command, and stores the output in the dist/<app-name>/ directory.

nx build api

Linting the application

Lint the application using the go fmt command.

nx lint api

Serving the application

Serves the application using the go run command.

nx serve api
Watch mode

To run the application in watch mode you can use gow, after installing it on your machine.

Find the key projects.<app-name>.architect.serve.options and set the cmd parameter to gow, like so:

{
  "projects": {
    "api": {
      "architect": {
        "serve": {
          "builder": "@nx-go/nx-go:serve",
          "options": {
            "cmd": "gow",
            "main": "apps/api/main.go"
          }
        }
      }
    }
  }
}

Testing the application

Test the application using the go test command.

nx test api

Docker

In order to build Docker containers from the Go api inside the Nx Workspace, there are 2 base images provided:

Using the base images:

# Use nxgo/cli as the base image to do the build
FROM nxgo/cli as builder

# Create app directory
WORKDIR /workspace

# Copy package.json and the lock file
COPY package.json yarn.lock /workspace/

# Install app dependencies
RUN yarn

# Copy source files
COPY . .

# Build apps
RUN yarn build api

# This is the stage where the final production image is built
FROM golang:1.14-alpine as final

# Copy over artifacts from builder image
COPY --from=builder /workspace/dist/apps/api /workspace/api

# Set environment variables
ENV PORT=3000
ENV HOST=0.0.0.0

# Expose default port
EXPOSE 3000

# Start server
CMD [ "/workspace/api" ]

MIT License

Created by Bram Borggreve.

FAQs

Package last updated on 27 Dec 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc