|
| 1 | +# API Proxy Service |
| 2 | + |
| 3 | +A lightweight API proxy service written in Go that supports multiple endpoints, rate limiting, and proxy rotation. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Multiple site/endpoint support |
| 8 | +- API key rotation |
| 9 | +- Rate limiting |
| 10 | +- SOCKS5 and HTTP proxy support |
| 11 | +- Detailed logging system |
| 12 | +- Docker support |
| 13 | +- CORS enabled |
| 14 | +- Customizable base path |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +### Using Docker Compose |
| 19 | + |
| 20 | +1. Clone the repository |
| 21 | +2. Configure your settings: |
| 22 | + - Copy `.env.example` to `.env` |
| 23 | + - Copy `config.json.example` to `config.json` |
| 24 | +3. Run the service: |
| 25 | + ```bash |
| 26 | + docker-compose up -d |
| 27 | + ``` |
| 28 | + |
| 29 | +### Manual Setup |
| 30 | + |
| 31 | +1. Install Go 1.22 or later |
| 32 | +2. Configure your settings in `config.json` |
| 33 | +3. Run the service: |
| 34 | + ```bash |
| 35 | + go run main.go |
| 36 | + ``` |
| 37 | + |
| 38 | +## Configuration |
| 39 | + |
| 40 | +### Environment Variables |
| 41 | + |
| 42 | +- `PORT`: Server port (default: 3003) |
| 43 | +- `LOG_LEVEL`: Logging level (debug, info, warn, error) |
| 44 | +- `COMPOSE_PROJECT_NAME`: Docker compose project name |
| 45 | +- `UID`: User ID for Docker |
| 46 | +- `GID`: Group ID for Docker |
| 47 | +- `DC_HTTP_PORT`: Docker container HTTP port |
| 48 | + |
| 49 | +### Config.json Structure |
| 50 | + |
| 51 | +```json |
| 52 | +{ |
| 53 | + "GLOBAL_SETTINGS": { |
| 54 | + "DIRECT_ACCESS": false, |
| 55 | + "BASE_PATH": "/proxy", |
| 56 | + "PROXIES": [ |
| 57 | + "socks5://user:pass@host:port", |
| 58 | + "http://user:pass@host:port" |
| 59 | + ] |
| 60 | + }, |
| 61 | + "SITES": { |
| 62 | + "site-name": { |
| 63 | + "domain": "https://api.example.com", |
| 64 | + "PROXY_TYPE": "header|query|path|direct", |
| 65 | + "KEY": "X-Api-Key", |
| 66 | + "VALUES": [ |
| 67 | + {"key1": 3}, |
| 68 | + {"key2": 3} |
| 69 | + ] |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +#### Configuration Fields |
| 76 | + |
| 77 | +- `BASE_PATH`: Base URL path for all proxy endpoints (default: "/proxy") |
| 78 | +- `PROXY_TYPE`: How the proxy should handle requests |
| 79 | + - Supported types: `header`, `query`, `path`, or `direct` |
| 80 | + - For `direct` type, `VALUES` should contain full target URLs |
| 81 | +- `KEY`: API key header name or query parameter name |
| 82 | +- `VALUES`: API keys with their rate limits |
| 83 | + |
| 84 | +## Usage |
| 85 | + |
| 86 | +### Making Requests |
| 87 | + |
| 88 | +The proxy service accepts requests in the following format: |
| 89 | + |
| 90 | +``` |
| 91 | +http://localhost:{PORT}{BASE_PATH}/{site-name}/{endpoint} |
| 92 | +``` |
| 93 | + |
| 94 | +Examples: |
| 95 | +```bash |
| 96 | +# Default configuration |
| 97 | +curl http://localhost:3003/proxy/myip4/ |
| 98 | + |
| 99 | +# Custom base path configuration |
| 100 | +curl http://localhost:3003/api/myip4/ |
| 101 | +``` |
| 102 | + |
| 103 | +### Logs |
| 104 | + |
| 105 | +Logs are written to both console and `proxy.log` file. View Docker container logs using: |
| 106 | + |
| 107 | +```bash |
| 108 | +docker-compose logs api-proxy |
| 109 | +``` |
| 110 | + |
| 111 | +## Development |
| 112 | + |
| 113 | +### Prerequisites |
| 114 | + |
| 115 | +- Go 1.22+ |
| 116 | +- Docker and Docker Compose (for containerized deployment) |
| 117 | + |
| 118 | +### Building |
| 119 | + |
| 120 | +```bash |
| 121 | +# Build locally |
| 122 | +go build -o api-proxy |
| 123 | + |
| 124 | +# Build Docker image |
| 125 | +docker-compose build |
| 126 | +``` |
| 127 | + |
| 128 | +## License |
| 129 | + |
| 130 | +MIT License |
0 commit comments