Installation Guide
This guide will walk you through setting up the GoApp project on your local machine for development.
1. Prerequisites
Before you begin, ensure you have the following installed:
- Go: Version 1.23 or later. You can check your version with
go version
. - Git: For cloning the repository.
- PostgreSQL: A running instance of PostgreSQL. You can install it directly or use Docker.
- (Optional) Docker & Docker Compose: Required for the Quick Start method.
2. Get the Source Code
Clone the repository from GitHub:
git clone https://github.com/naughtygopher/goapp.git
cd goapp
3. Install Dependencies
The project uses Go Modules to manage dependencies. You can download all the required modules by running:
go mod download
This command inspects the go.mod
file and downloads the necessary packages into your Go module cache.
4. Database Setup
The application requires a PostgreSQL database. You need to create a database and then apply the provided schemas.
Step 4.1: Create the Database
Connect to your PostgreSQL instance and create a new database and user. The docker-compose.yml
file uses the following defaults, which you can replicate:
- Database:
goapp
- User:
gauser
- Password:
gauserpassword
You can create these with the following SQL commands:
CREATE DATABASE goapp;
CREATE USER gauser WITH PASSWORD 'gauserpassword';
GRANT ALL PRIVILEGES ON DATABASE goapp TO gauser;
Step 4.2: Apply Schemas
Connect to your newly created goapp
database and run the SQL scripts located in the /schemas
directory. It's important to run them in the correct order.
1. functions.sql
: This sets up a trigger function to automatically update updated_at
timestamps.
-- From schemas/functions.sql
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
IF row(NEW.*) IS DISTINCT FROM row(OLD.*) THEN
NEW.updated_at = now();
RETURN NEW;
ELSE
RETURN OLD;
END IF;
END;
$$ language 'plpgsql';
2. users.sql
: This creates the users
table and applies the trigger.
-- From schemas/users.sql
CREATE TABLE IF NOT EXISTS users (
id UUID PRIMARY KEY,
email TEXT UNIQUE,
full_name TEXT,
phone TEXT,
contact_address TEXT,
created_at timestamptz DEFAULT now(),
updated_at timestamptz DEFAULT now()
);
CREATE TRIGGER tr_users_bu BEFORE UPDATE on users
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
3. user_notes.sql
: This creates the user_notes
table with a foreign key to users
and applies the trigger.
-- From schemas/user_notes.sql
CREATE TABLE IF NOT EXISTS user_notes (
id UUID PRIMARY KEY,
title TEXT,
content TEXT,
user_id UUID references users(id),
created_at timestamptz DEFAULT now(),
updated_at timestamptz DEFAULT now()
);
CREATE TRIGGER tr_users_bu BEFORE UPDATE on user_notes
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
5. Configuration
The application is configured using environment variables. To run the application manually, you'll need to set these variables. Create a .env
file or export them in your shell.
For a minimal setup, you need to provide the database connection details and the path to the HTML templates.
# Application Environment
export ENV=local
export APP_NAME=goapp
export APP_VERSION=v1.0.0
# Database Configuration
export POSTGRES_HOST=localhost
export POSTGRES_PORT=5432
export POSTGRES_STORENAME=goapp
export POSTGRES_USERNAME=gauser
export POSTGRES_PASSWORD=gauserpassword
# HTTP Server Configuration
export TEMPLATES_BASEPATH=${PWD}/cmd/server/http/web/templates
For a full list of configuration options, see the Configuration page.
Once these steps are complete, you are ready to run the application. See the Quick Start guide for instructions on running the server.