|
1 | | -# go-sql-proxy |
| 1 | +# Go-SQL-Proxy |
| 2 | + |
| 3 | +This project implements a SQL proxy server in Golang that acts as an intermediary between a client and a MySQL server. The proxy server can handle protocol decoding and data transfer while measuring and updating metrics for monitoring purposes. |
| 4 | + |
| 5 | +## Project Structure |
| 6 | + |
| 7 | +The project is structured as follows: |
| 8 | + |
| 9 | +- **pkg/** |
| 10 | + - **config/** |
| 11 | + - `config.go`: Contains the configuration settings and loads them from environment variables. |
| 12 | + - **logging/** |
| 13 | + - `logging.go`: Handles setting up and configuring the logger using Logrus. |
| 14 | + - **metrics/** |
| 15 | + - `metrics.go`: Implements metrics collection and exposes Prometheus metrics endpoints. |
| 16 | + - **health/** |
| 17 | + - `health.go`: Handles health check endpoints for database connectivity. |
| 18 | + - **protocol/** |
| 19 | + - `flags.go`: Defines MySQL capability flags used in the protocol. |
| 20 | + - `math.go`: Contains utility functions for mathematical operations. |
| 21 | + - `protocol.go`: Implements decoding and encoding of MySQL protocol packets. |
| 22 | + - **proxy/** |
| 23 | + - `NewConnection.go`: Creates a new proxy connection to the target MySQL server. |
| 24 | + - `NewProxy.go`: Creates a new instance of the Proxy server. |
| 25 | + - `HandleConnection.go`: Manages data transfer and protocol decoding for a connection. |
| 26 | + - `proxyHandle.go`: Handles a new connection request in a goroutine. |
| 27 | + - `transferData.go`: Handles data transfer between client and server while measuring latency. |
| 28 | + - `StartProxy.go`: Starts the proxy server and accepts incoming connections. |
| 29 | + - `EnableDecoding.go`: Enables protocol decoding for the proxy. |
| 30 | + - `handleProtocolDecoding.go`: Decodes the MySQL protocol handshake. |
| 31 | + - **models/** |
| 32 | + - `Proxy.go`: Defines the structure for the proxy server configuration and state. |
| 33 | + - `Connection.go`: Represents a connection to a MySQL server. |
| 34 | +- `main.go`: Main entry point of the proxy server application. |
| 35 | + |
| 36 | +## Running the Server |
| 37 | + |
| 38 | +To start the Go-SQL-Proxy server, the main entry point is `main.go`. The server can be started by running this file with the necessary environment variables configured to set up the proxy settings. |
| 39 | + |
| 40 | +To run the server, execute the following command: |
| 41 | + |
| 42 | +```bash |
| 43 | +go run main.go |
| 44 | +``` |
| 45 | + |
| 46 | +You can customize the server configurations by setting the environment variables as defined in `pkg/config/config.go`. |
| 47 | + |
| 48 | +## Note |
| 49 | + |
| 50 | +- This implementation serves as a basic demonstration of a SQL proxy server and may require additional features for production use. |
| 51 | +- Ensure proper configuration of database access and proxy settings before running the server in a production environment. |
| 52 | + |
| 53 | +Feel free to explore and extend this project for your specific use case or requirements! |
0 commit comments