Skip to content

Getting Started with Txlog Server ​

In this tutorial, you install the Txlog Server development environment on your computer. At the end, you have a server that uses a local database and can receive data.

Prerequisites ​

Install these tools first:

  • Go (version 1.27 or higher)
  • Node.js and npm (to build the CSS)
  • Docker (to run the database)
  • Make (to run build commands)
  • Git

Step 1: Clone the Repository ​

Clone the repository to your computer:

bash
git clone https://github.com/txlog/server.git
cd server

Step 2: Start the Database ​

Txlog Server uses a PostgreSQL database. For development, you can run PostgreSQL in a Docker container.

Run this command to start the container:

bash
docker run -d --name txlog-postgres \
  -e POSTGRES_USER=txlog \
  -e POSTGRES_PASSWORD=secret \
  -e POSTGRES_DB=txlog \
  -p 5432:5432 \
  postgres:15-alpine

This command:

  • Starts a container with the name txlog-postgres.
  • Sets the user and the database name to txlog, and the password to secret.
  • Opens port 5432 on your computer.

Step 3: Configure the Environment ​

Create a .env file in the root directory of the project. Copy this configuration, which connects to the database of step 2:

bash
# Server Configuration
INSTANCE=Local Dev
LOG_LEVEL=DEBUG
GIN_MODE=debug
PORT=8080

# Database Configuration
PGSQL_HOST=127.0.0.1
PGSQL_PORT=5432
PGSQL_USER=txlog
PGSQL_DB=txlog
PGSQL_PASSWORD=secret
PGSQL_SSLMODE=disable

# Cron Configuration (for background tasks)
CRON_RETENTION_DAYS=7
CRON_RETENTION_EXPRESSION=0 2 * * *
CRON_STATS_EXPRESSION=0 * * * *
CRON_OSV_EXPRESSION=0 4 * * *

Note: The value of PGSQL_SSLMODE is disable because the Postgres Docker image does not use SSL by default.

Step 4: Install Dependencies and Tools ​

The project uses these tools:

  • air builds and starts the server again when a file changes.
  • swag generates the API documentation.
  • Tailwind CSS makes the styles of the dashboard.

Install them with these commands:

bash
# Install Air (for live reload)
curl -fsSL https://install.rda.run/air-verse/air@latest! | bash

# Install Swaggo (for API docs)
curl -fsSL https://install.rda.run/swaggo/swag@latest! | bash

# Install Tailwind CSS
npm install

Step 5: Run the Server ​

Start the server. make run uses air, so the server restarts when you change a file.

bash
make run

The output shows that the server started:

text
...
time=... level=INFO msg="Database: connection established."
time=... level=INFO msg="Migrations: schema is up to date."
time=... level=INFO msg="Scheduler: started."
time=... level=INFO msg="No authentication configured - API endpoints accessible without API key"
[GIN-debug] Listening and serving HTTP on :8080

Step 6: Open the Dashboard ​

Open this address in your browser:

http://localhost:8080

The browser shows the Txlog Server dashboard. The dashboard is empty because the database is new.


Next step: To learn how to use the API of your server, do the Your First API Request tutorial.