Skip to content
generated from CDCgov/template

A complete rewrite of CDC's vocabulary management service, PHIN VADS, in Go.

Notifications You must be signed in to change notification settings

CDCgov/phinvads-go

Repository files navigation

phinvads-go

PHIN VADS written in Go. Load phinvads.dump into a PostgreSQL database using pg_restore, run the app with air, and go!

Getting Started

Clone down the repository:

git clone https://github.com/CDCgov/phinvads-go.git
cd phinvads-go

Create a .env file:

cp .env.sample .env

Installing and Configuring direnv

We use direnv to automatically set environment variables on a per-project basis. The .envrc file found in the project's directory tells direnv to read in the environment variables specified in the .env file.

Follow these steps to set up direnv on your machine:

  1. Install direnv (brew install direnv)
  2. Add a hook for your shell
  3. Restart your terminal
  4. Run direnv allow in the project directory

When navigating into the phinvads-go project directory, you should see something like this in your terminal, which lets you know that the environment variables are loaded:

direnv: export +DB_HOST +DB_NAME +DB_PASSWORD +DB_PORT +DB_USER +HOST +PORT

Local Development

In this section, we'll:

  1. Start PostgreSQL in a container or locally
  2. Load data into PostgreSQL
  3. Start the app

Running PostgreSQL in a Container

You may choose to manage your database using Docker. phinvads-go provides a Docker Compose file to allow for a streamlined database setup. Please download and install Rancher Desktop if you don't already have it installed.

Note: If you'd prefer to install PostgreSQL locally, please skip the rest of this section and refer to the Local Database Setup section instead.

To start your database, run this command:

make startdb

Next, please follow these steps in order to load in the data:

  1. Place phinvads.dump into the top level of your /phinvads-go project directory (Please let an engineering team member know if you need a copy of phinvads.dump)
  2. Navigate to the project directory and start your PostgreSQL database with make startdb (if the container isn't already running)
  3. Run make refreshdb to create the phinvads database and load in the data

Running the App

In order to run the app you'll need to have completed the following steps:

  1. Install Go

  2. Install air:

    go install github.com/air-verse/air@latest
  3. Install templ

    go install github.com/a-h/templ/cmd/templ@latest
  4. Install mkcert

  5. Create your own self-signed certs for local development:

    cd tls
    mkcert -install
    mkcert localhost
    cd ..

Once all dependencies have been installed, run this command:

make startapp

The application is now running and available in your browser at http://localhost:4000. As files are modified and saved, your application will automatically rebuild.

If you'd like to use live reloading in your browser when doing frontend work, you can make use of the templ proxy. The proxy can be accessed in your browser at http://localhost:7331. Changes to *.templ files will be automatically reflected in the browser.

You can stop running the app with ctrl + c.

Local Database Setup

If you'd prefer to not rely on Docker and instead run PostgreSQL locally, you will need to:

  1. Install and run PostgreSQL

  2. Create an empty database:

    psql -c 'CREATE DATABASE phinvads'
  3. Load the database dump file:

    pg_restore -d phinvads --no-owner --role=$(whoami) phinvads.dump

Linting

Pull requests to the main branch are required to pass linting checks. We use pre-commit to run these checks. To run them locally, install pre-commit and then install the hooks to run before every commit.

pip install pre-commit
pre-commit install

You can also run the checks on demand using pre-commit run (staged files) or pre-commit run --all-files (entire repo).

About

A complete rewrite of CDC's vocabulary management service, PHIN VADS, in Go.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published