32 lines
773 B
Go
32 lines
773 B
Go
|
|
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,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|