Skip to main content

Prerequisites

Before installing DefDrive locally, ensure you have the following installed:
  • Go 1.24.1 or higher - Download Go
  • PostgreSQL - A running PostgreSQL database instance
  • Git - For cloning the repository

Installation Steps

1

Clone the Repository

Clone the DefDrive repository from GitHub:
git clone https://github.com/yourusername/defdrive.git
cd defdrive
2

Install Dependencies

Install all required Go dependencies using:
go mod tidy
This will download and install all packages specified in go.mod, including:
  • Gin web framework
  • GORM (PostgreSQL driver)
  • JWT authentication
  • godotenv for environment variables
3

Configure Environment Variables

Create a .env file in the root directory:
cp .env.example .env
Edit the .env file with your configuration. See the Environment Variables page for detailed information about each variable.
Make sure to set a strong JWT_SECRET and configure your DATABASE_URL with valid PostgreSQL credentials.
4

Set Up PostgreSQL Database

Ensure PostgreSQL is running and create a database:
CREATE DATABASE defdrive;
The application will automatically create the required tables on first run using GORM’s AutoMigrate feature.
5

Run the Server

Start the DefDrive server:
go run main.go
The server will start on the port specified in your .env file (default: 8080).

Verify Installation

Once the server is running, you should see output similar to:
Connecting to database using DATABASE_URL
Database initialized successfully
Server starting on port 8080
Test the server by accessing:
curl http://localhost:8080/api/health

Database Connection

DefDrive includes automatic retry logic for database connections. If the initial connection fails, it will retry up to 5 times with a 5-second delay between attempts.
The application connects to PostgreSQL using the DATABASE_URL environment variable in the format:
postgres://username:password@host:port/database

Data Storage

By default, uploaded files are stored in the directory specified by the DATA_PATH environment variable (default: ./data). Make sure this directory exists and has proper write permissions:
mkdir -p ./data
chmod 755 ./data

Development Mode

For development, you can use go run for hot reloading, or consider using tools like:
  • air - Live reload for Go apps
  • reflex - Run commands when files change

Troubleshooting

Database Connection Issues

If you encounter database connection errors:
  1. Verify PostgreSQL is running:
    pg_isready
    
  2. Check your DATABASE_URL format
  3. Ensure the database exists
  4. Verify network connectivity to the database host

Port Already in Use

If port 8080 is already in use, change the PORT environment variable in your .env file:
PORT=3000

Next Steps

Build docs developers (and LLMs) love