https://github.com/architect/plugin-go
Go runtime + workflow integration for Architect
https://github.com/architect/plugin-go
Last synced: 28 days ago
JSON representation
Go runtime + workflow integration for Architect
- Host: GitHub
- URL: https://github.com/architect/plugin-go
- Owner: architect
- Created: 2023-03-28T17:39:08.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-29T17:04:45.000Z (about 3 years ago)
- Last Synced: 2025-02-07T21:37:36.778Z (over 1 year ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 1
- Watchers: 5
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Contributing: .github/contributing.md
- Code of conduct: .github/code_of_conduct.md
Awesome Lists containing this project
README

## [`@architect/plugin-go`](https://www.npmjs.com/package/@architect/plugin-go)
> Go runtime + workflow integration for Architect
[](https://github.com/architect/plugin-go/actions?query=workflow%3A%22Node+CI%22)
## Install
Into your existing Architect project:
```sh
npm i @architect/plugin-go --save-dev
```
Add the following to your Architect project manifest (usually `app.arc`):
```arc
@aws
runtime go # sets Go as the the default runtime for your entire project
@plugins
architect/plugin-go
```
Or, if you'd prefer to add a single Go Lambda to start, forego the above `runtime go` setting in your project manifest, and add the following to a single Lambda:
```arc
# src/http/get-index/config.arc
@aws
runtime go
```
## Usage
Now, simply author and port Lambdas in the `src` tree (with appropriate Cargo files). For example:
```go
// src/http/get-index/src/main.rs
#[macro_use]
extern crate json;
use json::{stringify};
use lambda_http::{run, service_fn, Body, Error, Request, Response};
#[tokio::main]
async fn main() -> Result<(), Error> {
run(service_fn(function_handler)).await
}
async fn function_handler(_event: Request) -> Result, Error> {
let body = object!{
ok: true,
};
let resp = Response::builder()
.status(200)
.header("content-type", "application/json")
.body(stringify(body).into())
.map_err(Box::new)?;
Ok(resp)
}
```
The above function will be automatically compiled by Architect to `./.build/http/get-index/` with `cargo build` (for local development) and `cargo lambda build` (for final deployment to Lambda) commands. (The destination build directory is configurable, [see below](#configuration).)
When working locally, Sandbox automatically detects changes to your Go handlers and re-compiles them for you.
## Configuration
### Lambda architecture
By default, Architect Go uses the Lambda architecture available in all regions: `x86_64`. However, if your app is deployed in a region that supports `arm64`, we strongly suggest configuring that like so in your project manifest:
```arc
@aws
architecture arm64
```
> Caveat: due to the way Architect runtime plugins work under the hood, Architect Go only respects the project's global architecture setting. If your project includes non-go Lambdas that need to use a different architecture, their architecture should be [configured individually via `config.arc`](https://arc.codes/docs/en/reference/configuration/function-config#architecture).
### Project manifest settings
The following higher-level settings are also available in your Architect project manifest with the `@go` settings pragma:
- `build` - customize the build directory; defaults to `.build`
- Note: make sure you add this directory to your `.gitignore`
Example:
```arc
@go
# Build into `./dist`
build dist
```
### Build output
`cargo` features fairly verbose output logging, which is disabled by default. To enable it, pass the CLI flag `--verbose|-v` or `--debug|-d`.