A Go web application built with Fiber framework and hexagonal architecture, featuring a PostgreSQL database and RESTful API. Designed for deployment on Jelastic cloud platform.
- HTTP server with Fiber framework
- Hexagonal architecture (ports and adapters)
- PostgreSQL database with GORM
- RESTful API for user management
- Database seeding system with sample data
- Environment variable configuration
- Request logging middleware
- Docker Compose for local development
- Makefile for easy development workflow
GET /- Returns a JSON health check message
POST /users- Create a new userGET /users- Get all usersGET /users/:id- Get user by IDPUT /users/:id- Update user by IDDELETE /users/:id- Delete user by ID
User JSON Structure:
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}Environment Variables:
PORT: Server port (default: 3000)TEST_MSG: Additional message to append to health checkDB_HOST: PostgreSQL host (default: localhost)DB_USER: Database user (default: postgres)DB_PASSWORD: Database password (default: password)DB_NAME: Database name (default: testdb)DB_PORT: Database port (default: 5432)DB_SSLMODE: SSL mode (default: disable)
- Go 1.20 or later
- Docker and Docker Compose
-
Clone the repository
git clone <repository-url> cd jelastic-golang-hello
-
Start PostgreSQL with Docker Compose
docker-compose up -d
-
Set up environment variables
cp .env.example .env # Edit .env if needed -
Install dependencies
go mod tidy
-
Run the application
go run main.go
-
Test the API
# Health check curl http://localhost:3000/ # Create a user curl -X POST http://localhost:3000/users \ -H "Content-Type: application/json" \ -d '{"name":"John Doe","email":"john@example.com"}' # Get all users curl http://localhost:3000/users # Get user by ID curl http://localhost:3000/users/1 # Update user curl -X PUT http://localhost:3000/users/1 \ -H "Content-Type: application/json" \ -d '{"name":"Jane Doe","email":"jane@example.com"}' # Delete user curl -X DELETE http://localhost:3000/users/1
Start PostgreSQL:
docker-compose up -dStop PostgreSQL:
docker-compose downView PostgreSQL logs:
docker-compose logs postgresConnect to PostgreSQL:
docker exec -it jelastic-postgres psql -U postgres -d testdbReset database (remove volume):
docker-compose down -v
docker-compose up -dThe application includes a comprehensive seeding system to populate the database with sample data.
Using Make commands (recommended):
# Run all seeders
make seed
# Run only user seeder
make seed-users
# Rollback all seeders
make rollback
# List available seeders
make list-seeders
# Setup development environment (starts DB + runs seeders)
make dev-setup
# Reset development environment (resets DB + runs seeders)
make dev-resetUsing Go commands directly:
# Run all seeders
go run cmd/seeder/main.go -action=seed
# Run specific seeder
go run cmd/seeder/main.go -action=seed -seeder=UserSeeder
# Rollback all seeders
go run cmd/seeder/main.go -action=rollback
# List available seeders
go run cmd/seeder/main.go -action=list
# Show help
go run cmd/seeder/main.go -helpUsing application flags:
# Run application with seeders
go run main.go -seed
# Run seeders only (don't start server)
go run main.go -seed-onlySample Data: The user seeder creates 10 sample users with realistic names and email addresses:
- John Doe (john.doe@example.com)
- Jane Smith (jane.smith@example.com)
- Bob Johnson (bob.johnson@example.com)
- And 7 more...
Creating Custom Seeders:
- Create a new seeder in
internal/seeder/ - Implement the
Seederinterface - Register it in
internal/seeder/registry.go
Deploy this application instantly to Jelastic cloud with our JPS manifest:
Or manually import:
- Go to Jelastic Import
- Use this URL:
https://raw.githubusercontent.com/Ruk-Com-Cloud/jelastic-golang-hello/main/manifest.jps - Click "Import" and follow the installation wizard
- Jelastic account
- Access to Jelastic dashboard
-
Create New Environment
- Log into your Jelastic dashboard
- Click "New Environment"
- Select "Go" as the programming language
- Choose Go version 1.19 or later
- Set environment name (e.g., "golang-hello")
- Configure topology as needed
- Click "Create"
-
Deploy Application
-
Option A: Git deployment (recommended)
- In Jelastic dashboard, go to your environment
- Click "Deployment Manager"
- Add your Git repository URL
- Click "Deploy to..."
- Select your Go application server
-
Option B: Archive upload
- Create a ZIP archive of your project
- Upload via Jelastic deployment manager
- Deploy to your Go server
-
-
Configure Environment Variables (Optional)
- Go to environment Settings
- Add environment variables:
PORT: Will be automatically set by JelasticTEST_MSG: Your custom message
-
Access Your Application
- Once deployed, Jelastic will provide a URL
- Test your endpoints:
https://your-env-name.app.ruk-com.cloud/https://your-env-name.app.ruk-com.cloud/?message=test
The application uses standard Go build process:
go build -o main .For Jelastic deployment, ensure your go.mod file is properly configured with Go 1.19+ and all dependencies are listed.
- Jelastic automatically sets the
PORTenvironment variable - The application listens on all interfaces (0.0.0.0)
- Logs are automatically collected by Jelastic monitoring
- SSL certificates are managed by Jelastic platform
MIT License - see LICENSE file for details.
