Skip to content

Commit d5ef7bd

Browse files
committed
struct updated
1 parent cc21028 commit d5ef7bd

File tree

12 files changed

+407
-767
lines changed

12 files changed

+407
-767
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.git
2+
.gitignore
3+
.env*
4+
README.md
5+
Dockerfile
6+
docker-compose.yml
7+
build/

Dockerfile

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
FROM golang:1.22.5-alpine AS builder
2-
# Install required system packages
3-
RUN apk update && \
4-
apk upgrade && \
5-
apk add --no-cache ca-certificates && \
6-
update-ca-certificates
2+
# Install required packages and set up workspace in a single layer
3+
RUN apk add --no-cache ca-certificates && update-ca-certificates
74

85
WORKDIR /build
96

10-
# Copy go mod and source files
11-
COPY go.mod go.sum ./
12-
COPY *.go ./
13-
14-
# Download dependencies
15-
RUN go mod download
7+
# Copy all necessary files in a single layer
8+
COPY . .
169

1710
# Build the application
18-
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server .
11+
RUN go mod download && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server ./cmd/main.go
1912

20-
# Final stage
13+
# Final stage - minimal image
2114
FROM scratch
2215
WORKDIR /app
23-
COPY --from=builder /build/proxy-server .
16+
17+
# Copy only the necessary files from builder
2418
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
19+
COPY --from=builder /build/proxy-server .
20+
COPY --from=builder /build/proxies.conf ./proxies.conf
21+
COPY --from=builder /build/users.conf ./users.conf
2522

2623
EXPOSE 1080
2724
CMD ["./proxy-server"]

README.md

Lines changed: 37 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -5,237 +5,99 @@ A high-performance SOCKS5 proxy server written in Go that rotates through multip
55
## Features
66

77
- SOCKS5 proxy server with username/password authentication
8-
- Support for multiple upstream proxy protocols:
9-
- HTTP proxies
10-
- HTTPS proxies (encrypted)
11-
- SOCKS5 proxies
12-
- SOCKS5H proxies (proxy performs DNS resolution)
8+
- Multiple proxy protocol support (HTTP, HTTPS, SOCKS5, SOCKS5H)
139
- Round-robin proxy rotation
1410
- Edge mode for fallback to direct connections
15-
- Multi-user support via configuration file
16-
- Docker and docker-compose support
17-
- Configurable port
11+
- Multi-user support
12+
- Docker support
1813
- Zero runtime dependencies
19-
- Comments support in configuration files
20-
- Automatic proxy failover
2114
- IPv6 support
2215

23-
## Quick Start with Docker Compose (Recommended)
16+
## Quick Start
2417

2518
1. Clone the repository:
2619
```bash
27-
git clone https://github.com/ariadata/go-proxy-rotator.git
20+
git clone https://github.com/yourusername/go-proxy-rotator.git
2821
cd go-proxy-rotator
2922
```
3023

3124
2. Set up configuration files:
3225
```bash
33-
# Copy environment example
3426
cp .env.example .env
35-
36-
# Create users file
37-
echo "user1:password1" > users.conf
38-
echo "user2:password2" >> users.conf
39-
40-
# Create proxies file (add your proxies)
41-
touch proxies.conf
27+
cp users.conf.example users.conf
28+
cp proxies.conf.example proxies.conf
4229
```
4330

44-
3. Create `docker-compose.yml`:
45-
```yaml
46-
version: '3.8'
47-
48-
services:
49-
proxy-rotator:
50-
image: 'ghcr.io/ariadata/go-proxy-rotator:latest'
51-
ports:
52-
- "${DC_SOCKS_PROXY_PORT}:1080"
53-
volumes:
54-
- ./proxies.conf:/app/proxies.conf:ro
55-
- ./users.conf:/app/users.conf:ro
56-
env_file:
57-
- .env
58-
restart: unless-stopped
59-
healthcheck:
60-
test: ["CMD", "nc", "-z", "localhost", "1080"]
61-
interval: 30s
62-
timeout: 10s
63-
retries: 3
64-
```
31+
3. Edit the configuration files:
32+
- `users.conf`: Add your username:password pairs
33+
- `proxies.conf`: Add your proxy servers
34+
- `.env`: Adjust settings if needed
6535

66-
4. Start the service:
36+
4. Run with Docker:
6737
```bash
68-
docker-compose up -d
69-
```
70-
71-
5. Test your connection:
72-
```bash
73-
curl --proxy socks5h://user1:password1@localhost:60255 https://api.ipify.org?format=json
74-
```
75-
76-
## Installation with Go
77-
78-
1. Clone and enter the repository:
79-
```bash
80-
git clone https://github.com/ariadata/go-proxy-rotator.git
81-
cd go-proxy-rotator
82-
```
83-
84-
2. Install dependencies:
85-
```bash
86-
go mod download
87-
```
88-
89-
3. Set up configuration files:
90-
```bash
91-
cp .env.example .env
92-
# Edit users.conf and proxies.conf
93-
```
94-
95-
4. Build and run:
96-
```bash
97-
go build -o proxy-server
98-
./proxy-server
38+
docker compose up -d
9939
```
10040

10141
## Configuration
10242

10343
### Environment Variables (.env)
104-
10544
```env
106-
# Project name for docker-compose
10745
COMPOSE_PROJECT_NAME=go-proxy-rotator
108-
109-
# Port for the SOCKS5 server
11046
DC_SOCKS_PROXY_PORT=60255
111-
112-
# Enable direct connections when proxies fail
11347
ENABLE_EDGE_MODE=true
11448
```
11549

11650
### User Configuration (users.conf)
117-
118-
Format:
11951
```
12052
username1:password1
12153
username2:password2
122-
# Comments are supported
12354
```
12455

12556
### Proxy Configuration (proxies.conf)
126-
127-
The proxy configuration file supports various proxy formats:
128-
12957
```
130-
# HTTP proxies
58+
# HTTP/HTTPS proxies
13159
http://proxy1.example.com:8080
132-
http://user:[email protected]:8080
133-
134-
# HTTPS proxies (encrypted connection to proxy)
135-
https://secure-proxy.example.com:8443
136-
https://user:[email protected]:8443
137-
138-
# SOCKS5 proxies (standard)
139-
socks5://socks-proxy.example.com:1080
140-
socks5://user:[email protected]:1080
60+
https://user:[email protected]:8443
14161
142-
# SOCKS5H proxies (proxy performs DNS resolution)
143-
socks5h://socks-proxy3.example.com:1080
144-
socks5h://user:[email protected]:1080
145-
146-
# IPv6 support
147-
http://[2001:db8::1]:8080
148-
socks5://user:password@[2001:db8::2]:1080
149-
150-
# Real-world format examples
151-
http://proxy-user:[email protected]:8080
152-
https://proxy-user:[email protected]:8443
153-
socks5://socks-user:[email protected]:1080
62+
# SOCKS5 proxies
63+
socks5://proxy3.example.com:1080
64+
socks5h://user:[email protected]:1080
15465
```
15566

156-
## Edge Mode
157-
158-
When edge mode is enabled (`ENABLE_EDGE_MODE=true`), the server will:
67+
## Testing
15968

160-
1. First attempt a direct connection
161-
2. If direct connection fails, rotate through available proxies
162-
3. If all proxies fail, return an error
163-
164-
This is useful for:
165-
- Accessing both internal and external resources
166-
- Reducing latency for local/fast connections
167-
- Automatic failover to direct connection
168-
169-
## Usage Examples
170-
171-
### With cURL
69+
Test your connection:
17270
```bash
173-
# Basic usage
174-
curl --proxy socks5h://user:pass@localhost:60255 https://api.ipify.org?format=json
175-
176-
# With specific DNS resolution
177-
curl --proxy socks5h://user:pass@localhost:60255 https://example.com
178-
179-
# With insecure mode (skip SSL verification)
180-
curl --proxy socks5h://user:pass@localhost:60255 -k https://example.com
71+
curl --proxy socks5h://username1:password1@localhost:60255 https://api.ipify.org?format=json
18172
```
18273

183-
### With Python Requests
184-
```python
185-
import requests
186-
187-
proxies = {
188-
'http': 'socks5h://user:pass@localhost:60255',
189-
'https': 'socks5h://user:pass@localhost:60255'
190-
}
74+
## Building from Source
19175

192-
response = requests.get('https://api.ipify.org?format=json', proxies=proxies)
193-
print(response.json())
76+
```bash
77+
make build
19478
```
19579

196-
### With Node.js
197-
```javascript
198-
const SocksProxyAgent = require('socks-proxy-agent');
199-
200-
const proxyOptions = {
201-
hostname: 'localhost',
202-
port: 60255,
203-
userId: 'user',
204-
password: 'pass',
205-
protocol: 'socks5:'
206-
};
207-
208-
const agent = new SocksProxyAgent(proxyOptions);
80+
## Docker Commands
20981

210-
fetch('https://api.ipify.org?format=json', { agent })
211-
.then(res => res.json())
212-
.then(data => console.log(data));
82+
Build image:
83+
```bash
84+
docker build -t go-proxy-rotator .
21385
```
21486

215-
## Building for Production
216-
217-
For production builds, use:
218-
87+
Run container:
21988
```bash
220-
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server .
89+
docker run -d \
90+
-p 60255:1080 \
91+
-v $(pwd)/proxies.conf:/app/proxies.conf:ro \
92+
-v $(pwd)/users.conf:/app/users.conf:ro \
93+
-e ENABLE_EDGE_MODE=true \
94+
go-proxy-rotator
22195
```
22296

223-
## Security Notes
224-
225-
- Always use strong passwords in `users.conf`
226-
- Consider using HTTPS/SOCKS5 proxies for sensitive traffic
227-
- The server logs minimal information for privacy
228-
229-
## Contributing
230-
231-
Contributions are welcome! Please feel free to submit a Pull Request.
232-
23397
## License
23498

23599
MIT License
236100

237-
## Acknowledgments
101+
## Contributing
238102

239-
Built using:
240-
- [go-socks5](https://github.com/armon/go-socks5) - SOCKS5 server implementation
241-
- Go's standard library for proxy and networking features
103+
Contributions are welcome! Please feel free to submit a Pull Request.

cmd/main.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"github.com/armon/go-socks5"
5+
"go-proxy-rotator/internal/config"
6+
"go-proxy-rotator/internal/proxy_dialer"
7+
"go-proxy-rotator/internal/proxy_manager"
8+
"log"
9+
)
10+
11+
func main() {
12+
// Load configuration
13+
cfg := config.NewConfig()
14+
15+
// Load user credentials
16+
credentials, err := config.LoadUserCredentials(cfg.UsersFile)
17+
if err != nil {
18+
log.Fatal(err)
19+
}
20+
21+
// Initialize proxy manager
22+
proxyManager := proxy_manager.NewManager(cfg.EnableEdgeMode)
23+
if err := proxyManager.LoadProxies(cfg.ProxiesFile); err != nil {
24+
log.Fatal(err)
25+
}
26+
27+
// Initialize proxy dialer
28+
dialer := proxy_dialer.NewProxyDialer(proxyManager)
29+
30+
// Create SOCKS5 server configuration with authentication
31+
serverConfig := &socks5.Config{
32+
Dial: dialer.Dial,
33+
Credentials: credentials,
34+
AuthMethods: []socks5.Authenticator{socks5.UserPassAuthenticator{
35+
Credentials: credentials,
36+
}},
37+
}
38+
39+
server, err := socks5.New(serverConfig)
40+
if err != nil {
41+
log.Fatal(err)
42+
}
43+
44+
log.Printf("SOCKS5 server running on %s (Edge Mode: %v, Users: %d)\n",
45+
cfg.ListenAddr,
46+
cfg.EnableEdgeMode,
47+
len(credentials))
48+
49+
// Start server
50+
if err := server.ListenAndServe("tcp", cfg.ListenAddr); err != nil {
51+
log.Fatal(err)
52+
}
53+
}

0 commit comments

Comments
 (0)