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:
git clone https://github.com/txlog/server.git
cd serverStep 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:
docker run -d --name txlog-postgres \
-e POSTGRES_USER=txlog \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=txlog \
-p 5432:5432 \
postgres:15-alpineThis command:
- Starts a container with the name
txlog-postgres. - Sets the user and the database name to
txlog, and the password tosecret. - Opens port
5432on 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:
# 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_SSLMODEisdisablebecause the Postgres Docker image does not use SSL by default.
Step 4: Install Dependencies and Tools
The project uses these tools:
airbuilds and starts the server again when a file changes.swaggenerates the API documentation.- Tailwind CSS makes the styles of the dashboard.
Install them with these commands:
# 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 installStep 5: Run the Server
Start the server. make run uses air, so the server restarts when you change a file.
make runThe output shows that the server started:
...
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 :8080Step 6: Open the Dashboard
Open this address in your browser:
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.
