A comprehensive Go-based REST API with advanced monitoring and metrics capabilities.
- PostgreSQL Integration: Robust database connectivity with connection pooling
- Health Monitoring: Multiple health check endpoints for different monitoring levels
- Comprehensive Metrics: Detailed system and database performance metrics
- CORS Support: Cross-origin resource sharing enabled for web applications
- Environment Configuration: Flexible configuration via environment variables or
.envfile - SSL/TLS Support: Secure database connections with certificate validation
All of the endpoints are described in detail here
The project includes an interactive HTML dashboard (readme.html) that provides:
- Real-time Metrics Display: Live updating dashboard with key metrics
- Endpoint Testing: Direct access to all API endpoints
- Response Visualization: Formatted JSON responses with syntax highlighting
- Performance Monitoring: Request latency measurements
- Memory Analysis: Detailed memory usage breakdown
To use the dashboard:
- Start the API server
- Open
readme.htmlin a web browser - The dashboard will automatically fetch and display metrics
- Go 1.19 or later
- PostgreSQL database (local or remote)
go mod tidy
go build -o astelta-api-v2 main.go./astelta-api-v2Configure the API using environment variables or a .env file:
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
Full PostgreSQL connection string | - |
DB_HOST |
Database host | - |
DB_PORT |
Database port | - |
DB_USER |
Database username | - |
DB_PASSWORD |
Database password | - |
DB_NAME |
Database name | - |
CA_CERT_PATH |
Path to CA certificate for SSL | - |
Using DATABASE_URL:
DATABASE_URL="postgres://user:password@host:port/database?sslmode=require"Using individual variables:
DB_HOST=localhost
DB_PORT=5432
DB_USER=myuser
DB_PASSWORD=mypassword
DB_NAME=mydatabase# With environment variables
export DB_HOST=your-host
export DB_USER=your-user
export DB_PASSWORD=your-password
./astelta-api-v2
# Or with .env file
./astelta-api-v2# Health check
curl http://localhost:8097/health
# Metrics
curl http://localhost:8097/metrics
# Database status
curl http://localhost:8097/db-status.
├── main.go # Main application file
├── readme.html # Interactive metrics dashboard
├── .gitignore # Git ignore rules
├── go.mod # Go module file
├── go.sum # Go dependencies
└── .env # Environment configuration (ignored)
- Database Connection: PostgreSQL connection with SSL support
- HTTP Handlers: RESTful endpoints with CORS middleware
- Metrics Collection: Runtime statistics and database monitoring
- Configuration Management: Environment variable parsing
- Error Handling: Comprehensive error responses
- Create a handler function:
func myHandler(w http.ResponseWriter, r *http.Request) {
// Handler logic
}- Register the endpoint in
main():
http.HandleFunc("/my-endpoint", corsMiddleware(myHandler))The API provides multiple levels of monitoring:
- Health Checks: Basic service availability
- Metrics: Detailed performance and resource usage data
- Database Monitoring: Connection health and query performance
- Memory Profiling: Go runtime memory statistics
Use these endpoints with monitoring tools like Prometheus, Grafana, or custom dashboards.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
Built with Go and PostgreSQL