This repository contains the source code for the Go API utilised by the 'Projects IDE' and is part of my submi
You will need to have Go installed on your machine. You can download Go from here.
You will be required to provide the following environment variables, these can be provided in a .env file in the root of the project:
PORT- The port that the API will run on (defaults to 8080)POSTGRES_PORT- The port that the Postgres database is running onPOSTGRES_HOST- The host that the Postgres database is running onPOSTGRES_USER- The username for the Postgres databasePOSTGRES_PASSWORD- The password for the Postgres databasePOSTGRES_DB- The name of the Postgres databaseS3_ACCESS_KEY_ID- AWS Access Key ID so that the API can access the S3 bucketS3_SECRET_ACCESS_KEY- AWS Secret Access Key so that the API can access the S3 bucketS3_BUCKET- The name of the S3 bucket that the API will use to store projectsJWT_SECRET- The secret used to sign the JWT tokensCORS_ALLOW_ORIGIN- The origin that the API will allow CORS requests fromDEPLOY_URL- The URL that the API will be deployed to
Prior to starting the server, you will need to perform a database migration so that the postgres database is setup correctly. To do this, run the following command:
go run main.go migrateThe server makes use of the following tools as part of its WebAssembly compilation pipeline:
- AssemblyScript - A TypeScript-like language that compiles to WebAssembly
- WebAssembly Binary Toolkit (wabt) - A toolkit for working with WebAssembly binaries and text formats
- TinyGo - A Go compiler for WebAssembly
You will need to ensure each of these are installed on your machine. Scripts for installing each of these dependencies are provided in the scripts directory. Run all of these scripts from the root of the project. Note that these scripts expect a Debian environment so for different environment it may be required to install these dependencies using other operating-system specific approaches.
Once you have setup environment variables and performed the necessary migrations, you can run the API by running the following command:
go run main.go serveThis will start the API on the port specified in the environment variables.
The provided Dockerfile can be used to build a Docker image for the API and is used to deploy the API in a production environment. Of course, you will need to provide the required environment variables to the Docker container when running it.
To run the unit tests for the API, run the following command:
go test ./...