This is geared towards Mac users, sorry in advance for any non-Mac environments. Anyways, this documentation is based on these amazing docs for installing and using Postgres, and the link covers Mac, Linux, and Window installations.
-
Install Postgres locally by following these instructions. (If using a Mac you will download the Postgres app)
-
Start up Postgres on port 5432 (if you have an error because there is already a process running on this port, you likely already have a previous version of postgres running. The following command should fix it:
sudo pkill -u postgres). -
Run
psqlto start a command-line client for interacting with Postgres (if you are having acommand not founderror and have a Mac, run the following command to link the command line tools with Postgres:sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp). -
Now that you are in the psql client, run the following commands to create a
gormdatabase along with agormuser (based on this documentation).CREATE USER gorm WITH PASSWORD 'gorm';CREATE DATABASE gorm;GRANT ALL PRIVILEGES ON DATABASE gorm to gorm;
-
Now you should be able to build and run the API without any issues. At this point, I would suggest installing a Postgres GUI Client for interacting with the gorm database, such as Postico for Mac. Here is the official list of clients
Prerequisites:
- Golang is installed
- Docker is installed
- Postgres is installed (should come with psql too)
- Postgres client is installed (optional but recommended)
With Golang
- Run
go buildto compile the executable from the file "main.go" - Run the executable named "api" (ex: if using mac run
./api)
With Docker
- Run
docker run -p 8080:8080 csci4950tgt/api
- Run
docker build -t csci4950tgt/api .to build the image - Run
docker push csci4950tgt/apito push new image to Docker repo
- Run
go test(orgo test -vif you want verbose information)