From 47d4f31ecd0dfc6d51ce85c2f4094ac8d6a9f5f7 Mon Sep 17 00:00:00 2001 From: Mehrdad Amini Date: Mon, 23 Dec 2024 23:15:55 +0300 Subject: [PATCH] update --- Dockerfile | 25 +- cmd/main.go | 53 ---- internal/config/config.go | 61 ---- internal/proxy_dialer/proxy_dialer.go | 242 -------------- internal/proxy_manager/proxy_manager.go | 112 ------- main.go | 404 ++++++++++++++++++++++++ makefile | 62 ---- 7 files changed, 418 insertions(+), 541 deletions(-) delete mode 100644 cmd/main.go delete mode 100644 internal/config/config.go delete mode 100644 internal/proxy_dialer/proxy_dialer.go delete mode 100644 internal/proxy_manager/proxy_manager.go create mode 100644 main.go delete mode 100644 makefile diff --git a/Dockerfile b/Dockerfile index eeb4c6c..12dba4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,27 @@ FROM golang:1.22.5-alpine AS builder -# Install required packages and set up workspace in a single layer -RUN apk add --no-cache ca-certificates && update-ca-certificates +# Install required system packages +RUN apk update && \ + apk upgrade && \ + apk add --no-cache ca-certificates && \ + update-ca-certificates WORKDIR /build -# Copy all necessary files in a single layer -COPY . . +# Copy go mod and source files +COPY go.mod go.sum ./ +COPY *.go ./ + +# Download dependencies +RUN go mod download # Build the application -RUN go mod download && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server ./cmd/main.go +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o proxy-server . -# Final stage - minimal image +# Final stage FROM scratch WORKDIR /app - -# Copy only the necessary files from builder -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /build/proxy-server . -COPY --from=builder /build/proxies.conf ./proxies.conf -COPY --from=builder /build/users.conf ./users.conf +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ EXPOSE 1080 CMD ["./proxy-server"] \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go deleted file mode 100644 index eb25b86..0000000 --- a/cmd/main.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "github.com/armon/go-socks5" - "go-proxy-rotator/internal/config" - "go-proxy-rotator/internal/proxy_dialer" - "go-proxy-rotator/internal/proxy_manager" - "log" -) - -func main() { - // Load configuration - cfg := config.NewConfig() - - // Load user credentials - credentials, err := config.LoadUserCredentials(cfg.UsersFile) - if err != nil { - log.Fatal(err) - } - - // Initialize proxy manager - proxyManager := proxy_manager.NewManager(cfg.EnableEdgeMode) - if err := proxyManager.LoadProxies(cfg.ProxiesFile); err != nil { - log.Fatal(err) - } - - // Initialize proxy dialer - dialer := proxy_dialer.NewProxyDialer(proxyManager) - - // Create SOCKS5 server configuration with authentication - serverConfig := &socks5.Config{ - Dial: dialer.Dial, - Credentials: credentials, - AuthMethods: []socks5.Authenticator{socks5.UserPassAuthenticator{ - Credentials: credentials, - }}, - } - - server, err := socks5.New(serverConfig) - if err != nil { - log.Fatal(err) - } - - log.Printf("SOCKS5 server running on %s (Edge Mode: %v, Users: %d)\n", - cfg.ListenAddr, - cfg.EnableEdgeMode, - len(credentials)) - - // Start server - if err := server.ListenAndServe("tcp", cfg.ListenAddr); err != nil { - log.Fatal(err) - } -} diff --git a/internal/config/config.go b/internal/config/config.go deleted file mode 100644 index 78bc725..0000000 --- a/internal/config/config.go +++ /dev/null @@ -1,61 +0,0 @@ -package config - -import ( - "bufio" - "fmt" - "github.com/armon/go-socks5" - "os" - "strings" -) - -type Config struct { - EnableEdgeMode bool - ProxiesFile string - UsersFile string - ListenAddr string -} - -func NewConfig() *Config { - return &Config{ - EnableEdgeMode: os.Getenv("ENABLE_EDGE_MODE") == "true", - ProxiesFile: "proxies.conf", - UsersFile: "users.conf", - ListenAddr: ":1080", - } -} - -func LoadUserCredentials(filename string) (socks5.StaticCredentials, error) { - credentials := make(socks5.StaticCredentials) - - file, err := os.Open(filename) - if err != nil { - return nil, err - } - defer func(file *os.File) { - _ = file.Close() - }(file) - - scanner := bufio.NewScanner(file) - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - if line == "" || strings.HasPrefix(line, "#") { - continue - } - - parts := strings.Split(line, ":") - if len(parts) != 2 { - return nil, fmt.Errorf("invalid credentials format in users.conf: %s", line) - } - credentials[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1]) - } - - if err := scanner.Err(); err != nil { - return nil, err - } - - if len(credentials) == 0 { - return nil, fmt.Errorf("no valid credentials found in users.conf") - } - - return credentials, nil -} diff --git a/internal/proxy_dialer/proxy_dialer.go b/internal/proxy_dialer/proxy_dialer.go deleted file mode 100644 index f54fd5c..0000000 --- a/internal/proxy_dialer/proxy_dialer.go +++ /dev/null @@ -1,242 +0,0 @@ -package proxy_dialer - -import ( - "bufio" - "context" - "crypto/tls" - "encoding/base64" - "fmt" - "io" - "net" - "net/http" - "net/url" -) - -type ProxyConfig struct { - ProxyURL *url.URL -} - -type ProxyManager interface { - GetNextProxy() (*ProxyConfig, error) - ShouldUseDirect() bool - HasProxies() bool - IsEdgeEnabled() bool -} - -type ProxyDialer struct { - manager ProxyManager -} - -func NewProxyDialer(manager ProxyManager) *ProxyDialer { - return &ProxyDialer{ - manager: manager, - } -} - -func (d *ProxyDialer) Dial(ctx context.Context, network, addr string) (net.Conn, error) { - var lastError error - - if d.manager.ShouldUseDirect() { - conn, err := net.Dial(network, addr) - if err == nil { - return conn, nil - } - lastError = err - } - - if d.manager.HasProxies() { - proxy, err := d.manager.GetNextProxy() - if err != nil { - if lastError != nil { - return nil, fmt.Errorf("direct connection failed: %v, proxy error: %v", lastError, err) - } - return nil, err - } - - conn, err := d.dialWithProxy(proxy, network, addr) - if err == nil { - return conn, nil - } - lastError = err - } else if !d.manager.IsEdgeEnabled() { - return nil, fmt.Errorf("no proxies available and edge mode is disabled") - } - - if lastError != nil { - return nil, fmt.Errorf("all connection attempts failed, last error: %v", lastError) - } - return nil, fmt.Errorf("no connection methods available") -} - -func (d *ProxyDialer) dialWithProxy(proxy *ProxyConfig, network, addr string) (net.Conn, error) { - switch proxy.ProxyURL.Scheme { - case "socks5", "socks5h": - return d.dialSocks5(proxy, addr) - case "http", "https": - return d.dialHTTP(proxy, network, addr) - default: - return nil, fmt.Errorf("unsupported proxy scheme: %s", proxy.ProxyURL.Scheme) - } -} - -func (d *ProxyDialer) dialSocks5(proxy *ProxyConfig, addr string) (net.Conn, error) { - conn, err := net.Dial("tcp", proxy.ProxyURL.Host) - if err != nil { - return nil, err - } - - if proxy.ProxyURL.User != nil { - err = performSocks5Handshake(conn, proxy.ProxyURL) - if err != nil { - _ = conn.Close() - return nil, err - } - } - - if err := sendSocks5Connect(conn, addr); err != nil { - _ = conn.Close() - return nil, err - } - - return conn, nil -} - -func (d *ProxyDialer) dialHTTP(proxy *ProxyConfig, network, addr string) (net.Conn, error) { - conn, err := net.Dial("tcp", proxy.ProxyURL.Host) - if err != nil { - return nil, err - } - - if proxy.ProxyURL.Scheme == "https" { - tlsConn := tls.Client(conn, &tls.Config{ - InsecureSkipVerify: true, - }) - if err := tlsConn.Handshake(); err != nil { - _ = conn.Close() - return nil, err - } - conn = tlsConn - } - - req := &http.Request{ - Method: "CONNECT", - URL: &url.URL{Opaque: addr}, - Host: addr, - Header: make(http.Header), - } - - if proxy.ProxyURL.User != nil { - basicAuth := base64.StdEncoding.EncodeToString([]byte(proxy.ProxyURL.User.String())) - req.Header.Set("Proxy-Authorization", "Basic "+basicAuth) - } - - if err := req.Write(conn); err != nil { - _ = conn.Close() - return nil, err - } - - resp, err := http.ReadResponse(bufio.NewReader(conn), req) - if err != nil { - _ = conn.Close() - return nil, err - } - if resp.StatusCode != 200 { - _ = conn.Close() - return nil, fmt.Errorf("proxy error: %s", resp.Status) - } - - return conn, nil -} - -func performSocks5Handshake(conn net.Conn, proxyURL *url.URL) error { - _, err := conn.Write([]byte{0x05, 0x01, 0x02}) - if err != nil { - return err - } - - resp := make([]byte, 2) - if _, err := io.ReadFull(conn, resp); err != nil { - return err - } - - if resp[0] != 0x05 || resp[1] != 0x02 { - return fmt.Errorf("unsupported auth method") - } - - username := proxyURL.User.Username() - password, _ := proxyURL.User.Password() - - auth := []byte{0x01} - auth = append(auth, byte(len(username))) - auth = append(auth, []byte(username)...) - auth = append(auth, byte(len(password))) - auth = append(auth, []byte(password)...) - - if _, err := conn.Write(auth); err != nil { - return err - } - - authResp := make([]byte, 2) - if _, err := io.ReadFull(conn, authResp); err != nil { - return err - } - - if authResp[1] != 0x00 { - return fmt.Errorf("authentication failed") - } - - return nil -} - -func sendSocks5Connect(conn net.Conn, addr string) error { - host, port, err := net.SplitHostPort(addr) - if err != nil { - return err - } - - req := []byte{0x05, 0x01, 0x00} - ip := net.ParseIP(host) - - if ip == nil { - req = append(req, 0x03, byte(len(host))) - req = append(req, []byte(host)...) - } else if ip4 := ip.To4(); ip4 != nil { - req = append(req, 0x01) - req = append(req, ip4...) - } else { - req = append(req, 0x04) - req = append(req, ip.To16()...) - } - - portNum := uint16(0) - _, _ = fmt.Sscanf(port, "%d", &portNum) - req = append(req, byte(portNum>>8), byte(portNum&0xff)) - - if _, err := conn.Write(req); err != nil { - return err - } - - resp := make([]byte, 4) - if _, err := io.ReadFull(conn, resp); err != nil { - return err - } - - if resp[1] != 0x00 { - return fmt.Errorf("connect failed: %d", resp[1]) - } - - switch resp[3] { - case 0x01: - _, err = io.ReadFull(conn, make([]byte, 4+2)) - case 0x03: - size := make([]byte, 1) - _, err = io.ReadFull(conn, size) - if err == nil { - _, err = io.ReadFull(conn, make([]byte, int(size[0])+2)) - } - case 0x04: - _, err = io.ReadFull(conn, make([]byte, 16+2)) - } - - return err -} diff --git a/internal/proxy_manager/proxy_manager.go b/internal/proxy_manager/proxy_manager.go deleted file mode 100644 index 7eac516..0000000 --- a/internal/proxy_manager/proxy_manager.go +++ /dev/null @@ -1,112 +0,0 @@ -package proxy_manager - -import ( - "bufio" - "fmt" - "go-proxy-rotator/internal/proxy_dialer" - "net/url" - "os" - "strings" - "sync" - "time" -) - -type Manager struct { - proxies []*proxy_dialer.ProxyConfig - currentIdx int - mu sync.Mutex - enableEdge bool - lastUsed time.Time -} - -func NewManager(enableEdge bool) *Manager { - return &Manager{ - proxies: make([]*proxy_dialer.ProxyConfig, 0), - enableEdge: enableEdge, - lastUsed: time.Now(), - } -} - -func (pm *Manager) LoadProxies(filename string) error { - file, err := os.Open(filename) - if err != nil { - if pm.enableEdge { - return nil - } - return err - } - defer func(file *os.File) { - _ = file.Close() - }(file) - - scanner := bufio.NewScanner(file) - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - if line == "" || strings.HasPrefix(line, "#") { - continue - } - - proxyURL, err := url.Parse(line) - if err != nil { - return fmt.Errorf("invalid proxy URL: %s", err) - } - - pm.proxies = append(pm.proxies, &proxy_dialer.ProxyConfig{ProxyURL: proxyURL}) - } - - if err := scanner.Err(); err != nil { - return err - } - - if len(pm.proxies) == 0 && !pm.enableEdge { - return fmt.Errorf("no proxies loaded from configuration and edge mode is disabled") - } - - return nil -} - -func (pm *Manager) GetNextProxy() (*proxy_dialer.ProxyConfig, error) { - pm.mu.Lock() - defer pm.mu.Unlock() - - if len(pm.proxies) == 0 { - return nil, fmt.Errorf("no proxies available") - } - - proxy := pm.proxies[pm.currentIdx] - pm.currentIdx = (pm.currentIdx + 1) % len(pm.proxies) - pm.lastUsed = time.Now() - - return proxy, nil -} - -func (pm *Manager) ShouldUseDirect() bool { - pm.mu.Lock() - defer pm.mu.Unlock() - - if !pm.enableEdge { - return false - } - - if len(pm.proxies) == 0 { - return true - } - - return time.Since(pm.lastUsed) > 5*time.Second -} - -func (pm *Manager) HasProxies() bool { - pm.mu.Lock() - defer pm.mu.Unlock() - return len(pm.proxies) > 0 -} - -func (pm *Manager) IsEdgeEnabled() bool { - return pm.enableEdge -} - -func (pm *Manager) ProxyCount() int { - pm.mu.Lock() - defer pm.mu.Unlock() - return len(pm.proxies) -} diff --git a/main.go b/main.go new file mode 100644 index 0000000..7304e6e --- /dev/null +++ b/main.go @@ -0,0 +1,404 @@ +package main + +import ( + "bufio" + "context" + "crypto/tls" + "encoding/base64" + "fmt" + "github.com/armon/go-socks5" + "io" + "log" + "net" + "net/http" + "net/url" + "os" + "strings" + "sync" + "time" +) + +type ProxyConfig struct { + proxyURL *url.URL +} + +type ProxyManager struct { + proxies []*ProxyConfig + currentIdx int + mu sync.Mutex + enableEdge bool + lastUsed time.Time +} + +func NewProxyManager(enableEdge bool) *ProxyManager { + return &ProxyManager{ + proxies: make([]*ProxyConfig, 0), + enableEdge: enableEdge, + lastUsed: time.Now(), + } +} + +func (pm *ProxyManager) LoadProxies(filename string) error { + file, err := os.Open(filename) + if err != nil { + if pm.enableEdge { + return nil + } + return err + } + defer func(file *os.File) { + _ = file.Close() + }(file) + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + + proxyURL, err := url.Parse(line) + if err != nil { + return fmt.Errorf("invalid proxy URL: %s", err) + } + + pm.proxies = append(pm.proxies, &ProxyConfig{proxyURL: proxyURL}) + } + + if err := scanner.Err(); err != nil { + return err + } + + if len(pm.proxies) == 0 && !pm.enableEdge { + return fmt.Errorf("no proxies loaded from configuration and edge mode is disabled") + } + + return nil +} + +func (pm *ProxyManager) GetNextProxy() (*ProxyConfig, error) { + pm.mu.Lock() + defer pm.mu.Unlock() + + if len(pm.proxies) == 0 { + return nil, fmt.Errorf("no proxies available") + } + + // Always increment the index + proxy := pm.proxies[pm.currentIdx] + pm.currentIdx = (pm.currentIdx + 1) % len(pm.proxies) + + // Update last used time + pm.lastUsed = time.Now() + + return proxy, nil +} + +func (pm *ProxyManager) ShouldUseDirect() bool { + pm.mu.Lock() + defer pm.mu.Unlock() + + if !pm.enableEdge { + return false + } + + // If we have no proxies, always use direct + if len(pm.proxies) == 0 { + return true + } + + // In edge mode with proxies, use direct connection periodically + // This ensures we rotate through direct connection as well + return time.Since(pm.lastUsed) > 5*time.Second +} + +type ProxyDialer struct { + manager *ProxyManager +} + +func (d *ProxyDialer) Dial(ctx context.Context, network, addr string) (net.Conn, error) { + var lastError error + + // Check if we should try direct connection first + if d.manager.ShouldUseDirect() { + conn, err := net.Dial(network, addr) + if err == nil { + return conn, nil + } + lastError = err + } + + // If we have proxies, try them + if len(d.manager.proxies) > 0 { + proxy, err := d.manager.GetNextProxy() + if err != nil { + if lastError != nil { + return nil, fmt.Errorf("direct connection failed: %v, proxy error: %v", lastError, err) + } + return nil, err + } + + conn, err := d.dialWithProxy(proxy, network, addr) + if err == nil { + return conn, nil + } + lastError = err + } else if !d.manager.enableEdge { + return nil, fmt.Errorf("no proxies available and edge mode is disabled") + } + + if lastError != nil { + return nil, fmt.Errorf("all connection attempts failed, last error: %v", lastError) + } + return nil, fmt.Errorf("no connection methods available") +} + +func (d *ProxyDialer) dialWithProxy(proxy *ProxyConfig, network, addr string) (net.Conn, error) { + switch proxy.proxyURL.Scheme { + case "socks5", "socks5h": + return d.dialSocks5(proxy, addr) + case "http", "https": + return d.dialHTTP(proxy, network, addr) + default: + return nil, fmt.Errorf("unsupported proxy scheme: %s", proxy.proxyURL.Scheme) + } +} + +func (d *ProxyDialer) dialSocks5(proxy *ProxyConfig, addr string) (net.Conn, error) { + conn, err := net.Dial("tcp", proxy.proxyURL.Host) + if err != nil { + return nil, err + } + + if proxy.proxyURL.User != nil { + err = performSocks5Handshake(conn, proxy.proxyURL) + if err != nil { + _ = conn.Close() + return nil, err + } + } + + if err := sendSocks5Connect(conn, addr); err != nil { + _ = conn.Close() + return nil, err + } + + return conn, nil +} + +func (d *ProxyDialer) dialHTTP(proxy *ProxyConfig, network, addr string) (net.Conn, error) { + conn, err := net.Dial("tcp", proxy.proxyURL.Host) + if err != nil { + return nil, err + } + + if proxy.proxyURL.Scheme == "https" { + tlsConn := tls.Client(conn, &tls.Config{ + InsecureSkipVerify: true, + }) + if err := tlsConn.Handshake(); err != nil { + _ = conn.Close() + return nil, err + } + conn = tlsConn + } + + req := &http.Request{ + Method: "CONNECT", + URL: &url.URL{Opaque: addr}, + Host: addr, + Header: make(http.Header), + } + + if proxy.proxyURL.User != nil { + basicAuth := base64.StdEncoding.EncodeToString([]byte(proxy.proxyURL.User.String())) + req.Header.Set("Proxy-Authorization", "Basic "+basicAuth) + } + + if err := req.Write(conn); err != nil { + _ = conn.Close() + return nil, err + } + + resp, err := http.ReadResponse(bufio.NewReader(conn), req) + if err != nil { + _ = conn.Close() + return nil, err + } + if resp.StatusCode != 200 { + _ = conn.Close() + return nil, fmt.Errorf("proxy error: %s", resp.Status) + } + + return conn, nil +} + +func loadUserCredentials(filename string) (socks5.StaticCredentials, error) { + credentials := make(socks5.StaticCredentials) + + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer func(file *os.File) { + _ = file.Close() + }(file) + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + + parts := strings.Split(line, ":") + if len(parts) != 2 { + return nil, fmt.Errorf("invalid credentials format in users.conf: %s", line) + } + credentials[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1]) + } + + if err := scanner.Err(); err != nil { + return nil, err + } + + if len(credentials) == 0 { + return nil, fmt.Errorf("no valid credentials found in users.conf") + } + + return credentials, nil +} + +func main() { + // Load user credentials from file + credentials, err := loadUserCredentials("users.conf") + if err != nil { + log.Fatal(err) + } + + // Check if edge mode is enabled + enableEdge := os.Getenv("ENABLE_EDGE_MODE") == "true" + + // Initialize proxy manager + proxyManager := NewProxyManager(enableEdge) + if err := proxyManager.LoadProxies("proxies.conf"); err != nil { + log.Fatal(err) + } + + dialer := &ProxyDialer{manager: proxyManager} + + // Create SOCKS5 server configuration with authentication + conf := &socks5.Config{ + Dial: dialer.Dial, + Credentials: credentials, + AuthMethods: []socks5.Authenticator{socks5.UserPassAuthenticator{ + Credentials: credentials, + }}, + } + + server, err := socks5.New(conf) + if err != nil { + log.Fatal(err) + } + + log.Printf("SOCKS5 server running on :1080 (Edge Mode: %v, Users: %d, Proxies: %d)\n", + enableEdge, len(credentials), len(proxyManager.proxies)) + + // Always listen on port 1080 inside container + if err := server.ListenAndServe("tcp", ":1080"); err != nil { + log.Fatal(err) + } +} + +func performSocks5Handshake(conn net.Conn, proxyURL *url.URL) error { + _, err := conn.Write([]byte{0x05, 0x01, 0x02}) + if err != nil { + return err + } + + resp := make([]byte, 2) + if _, err := io.ReadFull(conn, resp); err != nil { + return err + } + + if resp[0] != 0x05 || resp[1] != 0x02 { + return fmt.Errorf("unsupported auth method") + } + + username := proxyURL.User.Username() + password, _ := proxyURL.User.Password() + + auth := []byte{0x01} + auth = append(auth, byte(len(username))) + auth = append(auth, []byte(username)...) + auth = append(auth, byte(len(password))) + auth = append(auth, []byte(password)...) + + if _, err := conn.Write(auth); err != nil { + return err + } + + authResp := make([]byte, 2) + if _, err := io.ReadFull(conn, authResp); err != nil { + return err + } + + if authResp[1] != 0x00 { + return fmt.Errorf("authentication failed") + } + + return nil +} + +func sendSocks5Connect(conn net.Conn, addr string) error { + host, port, err := net.SplitHostPort(addr) + if err != nil { + return err + } + + req := []byte{0x05, 0x01, 0x00} + ip := net.ParseIP(host) + + if ip == nil { + req = append(req, 0x03, byte(len(host))) + req = append(req, []byte(host)...) + } else if ip4 := ip.To4(); ip4 != nil { + req = append(req, 0x01) + req = append(req, ip4...) + } else { + req = append(req, 0x04) + req = append(req, ip.To16()...) + } + + portNum := uint16(0) + _, _ = fmt.Sscanf(port, "%d", &portNum) + req = append(req, byte(portNum>>8), byte(portNum&0xff)) + + if _, err := conn.Write(req); err != nil { + return err + } + + resp := make([]byte, 4) + if _, err := io.ReadFull(conn, resp); err != nil { + return err + } + + if resp[1] != 0x00 { + return fmt.Errorf("connect failed: %d", resp[1]) + } + + switch resp[3] { + case 0x01: + _, err = io.ReadFull(conn, make([]byte, 4+2)) + case 0x03: + size := make([]byte, 1) + _, err = io.ReadFull(conn, size) + if err == nil { + _, err = io.ReadFull(conn, make([]byte, int(size[0])+2)) + } + case 0x04: + _, err = io.ReadFull(conn, make([]byte, 16+2)) + } + + return err +} diff --git a/makefile b/makefile deleted file mode 100644 index 6fe9729..0000000 --- a/makefile +++ /dev/null @@ -1,62 +0,0 @@ -.PHONY: run build test clean git-update docker-build docker-run - -# Binary name -BINARY_NAME=proxy-server -BUILD_DIR=build - -# Go parameters -GOCMD=go -GOBUILD=$(GOCMD) build -GOCLEAN=$(GOCMD) clean -GOTEST=$(GOCMD) test -GOGET=$(GOCMD) get -GOMOD=$(GOCMD) mod - -# Main package path -MAIN_PACKAGE=./cmd/main.go - -# Build flags -BUILD_FLAGS=-ldflags="-s -w" -trimpath - -all: test build - -run: - $(GOCMD) run $(MAIN_PACKAGE) - -build: - mkdir -p $(BUILD_DIR) - CGO_ENABLED=0 $(GOBUILD) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE) - -build-linux: - mkdir -p $(BUILD_DIR) - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PACKAGE) - -build-windows: - mkdir -p $(BUILD_DIR) - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PACKAGE) - -build-mac: - mkdir -p $(BUILD_DIR) - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PACKAGE) - -test: - $(GOTEST) -v ./... - -clean: - $(GOCLEAN) - rm -rf $(BUILD_DIR) - -deps: - $(GOGET) -v ./... - $(GOMOD) tidy - -docker-build: - docker build -t $(BINARY_NAME) . - -docker-run: - docker run -p 1080:1080 $(BINARY_NAME) - -git-update: - git add . - git commit -am "update" - git push \ No newline at end of file