From 8476340f75a0bc94097d1fe1090681572087e1ec Mon Sep 17 00:00:00 2001 From: Savely Krendelhoff Date: Sat, 23 Aug 2025 12:46:17 +0700 Subject: [PATCH] [PHASE-6] Define server configuration --- internal/server/config.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 internal/server/config.go diff --git a/internal/server/config.go b/internal/server/config.go new file mode 100644 index 0000000..3047106 --- /dev/null +++ b/internal/server/config.go @@ -0,0 +1,31 @@ +package server + +import "time" + +// Config holds configuration for the TCP server +type Config struct { + Address string + Timeouts TimeoutConfig +} + +// TimeoutConfig holds timeout configuration +type TimeoutConfig struct { + // Read timeout protects against slowloris attacks (clients sending data slowly) + Read time.Duration + // Write timeout protects against slow readers (clients reading responses slowly) + Write time.Duration + // Connection timeout is the maximum total connection lifetime + Connection time.Duration +} + +// DefaultConfig returns default server configuration +func DefaultConfig() *Config { + return &Config{ + Address: ":8080", + Timeouts: TimeoutConfig{ + Read: 5 * time.Second, + Write: 5 * time.Second, + Connection: 15 * time.Second, + }, + } +}