This project is a Gateway service implemented in Go using the HTTP module, Reverse proxy Gin framework. It includes features like load balancing, JWT authentication, logging, middleware handling, and dynamic management of backend servers. The service allows for adding, updating, and deleting backend servers via HTTP endpoints.
- Load Balancing Logic: Distributes traffic across multiple backend servers.
- JWT Authentication: Provides secure endpoints with JWT-based authentication.
- Logging: Logs requests and responses with custom log management, including writing logs with semaphores for concurrency control.
- Middleware: Includes default middleware for logging, error handling, and request validation.
- Server Management: Dynamically add, update, or delete backend servers.
- Error Handling: Handles various error cases like missing parameters, unsupported HTTP methods, and internal server errors.
- Go 1.18 or higher
- Gin framework
-
Clone the repository:
git clone https://github.com/yourusername/your-repository.git cd your-repository
-
Install dependencies:
go mod tidy
-
Run the application:
go run main.go
The service will be available on http://localhost:8080
.
- POST
/servers
- Adds a new backend server to the specified path.
- Request body: JSON representation of the server.
- DELETE
/servers
- Deletes an existing backend server.
- Query Parameters:
path
(required),url
(required).
- PUT
/servers
- Updates an existing backend server.
- Request body: JSON representation of the updated server.
- Query Parameter:
path
(required).
- GET
/servers
- Lists all servers for the specified path.
- Query Parameter:
path
(required).
- GET
/logs
- Fetches the log file content.
- Note: The log file must be initialized for this endpoint to work.
The gateway and server management behavior is configured via environment variables and config files. For example, the JWT configuration and log file paths can be set in the config file. The config file is in toml
format
- Secret Key: Used to sign and verify JWT tokens.
- Token Expiration: Set the expiration time for the JWT tokens.
- The logs are written using semaphores to handle concurrency.
- Log data includes request details and error messages.
If you find a bug or want to add new features, feel free to open an issue or create a pull request
[] Frontend Client
[] Persist config in DB for high reliability
[] Cleanups