Skip to content

gistsapp/api

Repository files navigation

Gists.app API - Code snippets and scripts safe

Go Report Card GitHub release (latest SemVer)

Usage

Check the API documentation for more information (for now this page is hosted locally, so please run the project before accessing the documentation).

Quick Start

Pre-requisites

  • Go (version 1.22+)
  • Air
  • docker compose
  • migrate
  • Just

Onboarding script

docker compose up -d
just migrate
just dev

Installation

  1. Make sure that you have air
go install github.com/air-verse/air@latest
  1. Clone the repository
  2. Provide the following environment variables in the .env file
# for now none needed
PORT="4000"
PG_USER="postgres"
PG_PASSWORD="postgres"
PG_PORT="5432"
PG_HOST="0.0.0.0"
PG_DATABASE="gists"
PUBLIC_URL="http://localhost:4000"
FRONTEND_URL="http://localhost:3000"
GOOGLE_KEY="<REDACTED>"
GOOGLE_SECRET="<REDACTED>"
GITHUB_KEY="<REDACTED>"
GITHUB_SECRET="<REDACTED>"
MAIL_SMTP="<REDACTED>"
MAIL_PASSWORD="<REDACTED>"
SMTP_PORT="<REDACTED>"
SMTP_HOST="<REDACTED>"
APP_KEY="<REDACTED>"
ENV="development"
  1. Run the server in development mode
just dev
# or
air

Configuration

All the configuration is done through env variables :

  • PORT : the port on which your web server runs
  • PG_USER : the postgres user
  • PG_PASSWORD : the postgres password
  • PG_PORT : the postgres port
  • PG_HOST : the postgres host
  • PG_DATABASE : the postgres database
  • PUBLIC_URL : The URL on which your application is available. If you use a reverse proxy to make your app available, you need to provide its URL thanks to this variable. It is mainly use as the redirection URL used during the authentication flow.
  • FRONTEND_URL : The URL on which your frontend is available. It is mainly use to set the cookie after the authentication flow
  • GOOGLE_KEY : your google client key for OAUTH2
  • GOOGLE_SECRET : your google client secret for OAUTH2
  • GITHUB_KEY : your github client key for OAUTH2
  • GITHUB_SECRET : your github client secret for OAUTH2
  • MAIL_SMTP : your smtp server
  • MAIL_PASSWORD : your smtp password
  • SMTP_PORT : your smtp port
  • SMTP_HOST : your smtp host
  • APP_KEY : your app key, which is a random string that is used to encrypt access tokens
  • ENV: the environment in which the app is running (development, production)

Tests

To run tests, execute:

just test <your-test-name>
# or to run all tests
just test-all

Migrations

For migrations we use migrate.

To create a migration run the following command :

migrate create -ext=sql -dir=migrations -seq init

To run the existing migrations locally :

just migrate
# or
migrate -path=migrations -database "postgresql://postgres:[email protected]:5432/gists?sslmode=disable" -verbose up

To rollback a migration :

migrate -path=migrations -database "postgresql://postgres:postgres@localhost:5432/gists?sslmode=disable" -verbose down 1

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages