mirror of
https://github.com/shlldev/miniws.git
synced 2025-09-03 11:20:59 +02:00
client rate limiting
This commit is contained in:
23
main.go
23
main.go
@@ -9,11 +9,14 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
HELP_PORT string = "what port miniws will run on"
|
||||
HELP_LOGFOLDER string = "the logs folder"
|
||||
HELP_CONFIGFOLDER string = "the configurations folder"
|
||||
HELP_WWWFOLDER string = "the www folder where miniws will look for files to serve"
|
||||
HELP_MAXLOGBYTES string = "the maximum bytes after which the log files get split"
|
||||
HELP_PORT string = "what port miniws will run on"
|
||||
HELP_LOGFOLDER string = "the logs folder"
|
||||
HELP_CONFIGFOLDER string = "the configurations folder"
|
||||
HELP_WWWFOLDER string = "the www folder where miniws will look for files to serve"
|
||||
HELP_MAXLOGBYTES string = "the maximum bytes after which the log files get split"
|
||||
HELP_MAXCLIENTRATE string = "the maximum number of requests per minute that any particular " +
|
||||
"client can send. exceeding this rate will cause miniws to reply with HTTP error 429: " +
|
||||
"Too Many Requests."
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -24,6 +27,7 @@ func main() {
|
||||
configFolder := parser.String("c", "config-folder", &argparse.Options{Default: "config", Help: HELP_CONFIGFOLDER})
|
||||
wwwFolder := parser.String("w", "www-folder", &argparse.Options{Default: ".", Help: HELP_WWWFOLDER})
|
||||
maxLogBytes := parser.Int("b", "max-log-bytes", &argparse.Options{Default: 1048576, Help: HELP_MAXLOGBYTES})
|
||||
maxClientRatePerMin := parser.Int("r", "max-client-rate", &argparse.Options{Default: 600, Help: HELP_MAXCLIENTRATE})
|
||||
|
||||
err := parser.Parse(os.Args)
|
||||
if err != nil {
|
||||
@@ -33,6 +37,13 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
webserver := miniws.NewWebServer(*port, *logFolder, *configFolder, *wwwFolder, int64(*maxLogBytes))
|
||||
webserver := miniws.NewWebServer(miniws.WebServerConfig{
|
||||
LogFolder: *logFolder,
|
||||
ConfigFolder: *configFolder,
|
||||
WWWFolder: *wwwFolder,
|
||||
Port: uint16(*port),
|
||||
MaxBytesPerLogFile: uint64(*maxLogBytes),
|
||||
MaxConnectionsPerMinute: uint64(*maxClientRatePerMin),
|
||||
})
|
||||
webserver.Run()
|
||||
}
|
||||
|
Reference in New Issue
Block a user