Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@nx-go/nx-go
Advanced tools
nx-go Nx plugin to use Go in a Nx workspace. Using nx-go in your company? Co
Nx plugin to use Go in a Nx workspace.
First, make sure you have a Nx Workspace.
Create a new one using the following command:
pnpm dlx create-nx-workspace go-playground --preset=empty --cli=nx --nx-cloud true
## Or using yarn
# yarn create nx-workspace go-playground --preset=empty --cli=nx --nx-cloud true
## Or using npm
# npm exec create-nx-workspace go-playground --preset=empty --cli=nx --nx-cloud true
cd go-playground
Next, install the nx-go plugin:
pnpm add -D @nx-go/nx-go
## Or using yarn
# yarn add -D @nx-go/nx-go
## Or using npm
# npm install -D @nx-go/nx-go
Create a new application:
nx g @nx-go/nx-go:app api
You can now run the Nx workspace commands:
This command builds the application using the go build
command, and stores the output in the dist/<app-name>/
directory.
nx build api
Lint the application using the go fmt
command.
nx lint api
Serves the application using the go run
command.
nx serve api
To run the application in watch mode you can use gow
, after installing it on your machine.
Open the file apps/<app-name>/project.json
and in the targets.serve.options
object and set the cmd
parameter to gow
and the cwd
parameter to .
, like so:
{
targets: {
serve: {
executor: '@nx-go/nx-go:serve',
options: {
cmd: 'gow', // This is the cmd that will be used
cwd: '.', // Set working dir to project root so it picks up changes in `libs/*`
main: 'apps/api/main.go',
},
},
},
}
Test the application using the go test
command.
nx test api
In order to build Docker containers from the Go api inside the Nx Workspace, there are 2 base images provided:
# 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.17-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" ]
Created by Bram Borggreve.
FAQs
Nx plugin to use Go in a Nx Workspace
The npm package @nx-go/nx-go receives a total of 16,543 weekly downloads. As such, @nx-go/nx-go popularity was classified as popular.
We found that @nx-go/nx-go demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.