Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Web App

Overview

This is a Golang web application that uses:

  • PostgreSQL for persistent storage
  • Redis for session management
  • AWS S3 for media storage
  • CloudFront (optional) for CDN-backed media delivery
  • golang-migrate for database migrations

The application can be run locally using Docker Compose and deployed to production as a single Go executable, with migrations executed separately.


Running the App Locally

Prerequisites

  • Go 1.20+
  • Docker & Docker Compose
  • AWS CLI
  • Make

Local Setup Instructions

  1. Generate an application secret key
openssl rand -hex 32
e7ca0377e91a43a5b0a2b30978339e11cbcb1dd4578da7a00fad89bf085acd3b

Set it as an environment variable:

APP_SECRET=<generated_secret>
  1. Configure AWS S3 and CloudFront (optional)
  • Create an S3 bucket for storing profile images.
  • (Optional) Set up a CloudFront distribution with read access to the bucket.
  • Ensure you have an IAM user with s3:PutObject permission.

Set the environment variables:

AWS_REGION=<aws_region>
AWS_S3_BUCKET=<s3_bucket_name>
MEDIA_BASE_URL=<https://cloudfront_or_s3_base_url>

MEDIA_BASE_URL must include https://.

  1. Install and configure AWS CLI
aws configure

Verify credentials:

aws sts get-caller-identity

A successful response includes UserId, Account, Arn.

  1. Start all services
docker compose up
  1. Run database migrations
make migrate-up

This step does the following

  • Apply the migrations.
  • Remove the container of the migrate service since it is no longer needed.
  1. Verify the application

Visit in a browser:


Deployment to Production

One-Time Infrastructure Setup

  1. PostgreSQL

Provision a database and set:

DATABASE_URL=postgres://user:password@host:port/dbname?sslmode=disable
  1. Redis

Provision Redis and set:

REDIS_ADDR=<host:port>
REDIS_PASSWORD=<password>
REDIS_DB=<db_number>
SESSION_TTL_HOURS=<hours>
  1. AWS S3 & CloudFront
  • Create an S3 bucket for media storage.
  • (Optional) Configure CloudFront distribution for read access.
  • Ensure IAM user has s3:PutObject permission.
  • Configure AWS CLI on production:
aws configure

Deployment Steps

  1. Transfer migration files to the server
scp -r migrations user@server:/opt/myapp/
  1. Run database migrations
migrate -path /opt/myapp/migrations -database "$DATABASE_URL" up
  1. Set AWS-related environment variables
AWS_REGION=<production_region>
AWS_S3_BUCKET=<production_bucket>
MEDIA_BASE_URL=<https://cloudfront_or_s3_base_url>
  1. Build the Go executable
go build -o myapp ./cmd/web
  1. Transfer the binary to the server
scp myapp user@server:/opt/myapp/
  1. Run the application
./myapp
  1. Verify deployment

Check all API endpoints and web routes to ensure they work.


Notes & Best Practices

  • Migrations are not run automatically; run them before starting the app.
  • Media URLs are stored as absolute HTTPS URLs.
  • AWS credentials are resolved via the standard AWS chain (~/.aws/credentials, IAM roles).
  • The app binary is stateless and safe for horizontal scaling.

About

A global chat application where users can participate in text messaging by joining chat rooms. Both registered and anonymous access are supported.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages