|
| 1 | +# Codebase Structure |
| 2 | + |
| 3 | +This document provides an overview of the Go codebase organization. |
| 4 | + |
| 5 | +## Directory Structure |
| 6 | + |
| 7 | +``` |
| 8 | +/ |
| 9 | +├── cmd/proxy-go/ |
| 10 | +│ └── main.go # Application entry point |
| 11 | +└── internal/ |
| 12 | + ├── debug/ # Go profiling support |
| 13 | + ├── env/ # Configuration management |
| 14 | + ├── errors/ # Error handling with stack traces |
| 15 | + ├── lb/ # Load balancer (memory/Redis) |
| 16 | + ├── logger/ # Logging and request tracing |
| 17 | + ├── protocol/ # Protocol servers (RTMP, HTTP, WebRTC, SRT, API) |
| 18 | + ├── rtmp/ # RTMP protocol implementation |
| 19 | + ├── signal/ # Graceful shutdown handling |
| 20 | + ├── sync/ # Concurrency utilities |
| 21 | + ├── utils/ # Common utilities |
| 22 | + └── version/ # Version information |
| 23 | +``` |
| 24 | + |
| 25 | +## Internal Packages |
| 26 | + |
| 27 | +### debug |
| 28 | +Go profiling support via pprof, controlled by `GO_PPROF` environment variable. |
| 29 | + |
| 30 | +### env |
| 31 | +Configuration management using environment variables. Loads `.env` file and provides defaults for all server settings. |
| 32 | + |
| 33 | +### errors |
| 34 | +Enhanced error handling with stack traces. Provides error wrapping and root cause extraction. |
| 35 | + |
| 36 | +### lb |
| 37 | +Load balancer system supporting both single-proxy (memory-based) and multi-proxy (Redis-based) deployments. |
| 38 | +- `lb.go` - Core interfaces and types |
| 39 | +- `mem.go` - Memory-based load balancer |
| 40 | +- `redis.go` - Redis-based load balancer |
| 41 | +- `debug.go` - Default backend for testing |
| 42 | + |
| 43 | +### logger |
| 44 | +Structured logging with context-based request tracing. Provides log levels: Verbose, Debug, Warning, Error. |
| 45 | + |
| 46 | +### protocol |
| 47 | +Protocol server implementations for all supported streaming protocols: |
| 48 | +- `rtmp.go` - RTMP protocol stack |
| 49 | +- `http.go` - HTTP streaming (HLS, HTTP-FLV, HTTP-TS) |
| 50 | +- `rtc.go` - WebRTC server (WHIP/WHEP) |
| 51 | +- `srt.go` - SRT server |
| 52 | +- `api.go` - HTTP API server |
| 53 | + |
| 54 | +### rtmp |
| 55 | +Low-level RTMP protocol implementation including handshake and AMF0 serialization. |
| 56 | + |
| 57 | +### signal |
| 58 | +Graceful shutdown coordination. Catches SIGINT/SIGTERM and implements timeout-based shutdown. |
| 59 | + |
| 60 | +### sync |
| 61 | +Thread-safe generic Map wrapper around `sync.Map` for connection tracking and caching. |
| 62 | + |
| 63 | +### utils |
| 64 | +Common utility functions for HTTP responses, JSON marshaling, and parsing. |
| 65 | + |
| 66 | +### version |
| 67 | +Version information and server identification. |
0 commit comments