diff --git a/README.md b/README.md index c033cad..4bfce32 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,6 @@ You need Go 1.13+ to compile the binary. bind_address="127.0.0.1" # backend listen port, default is 8989 listen_port=8989 - # download test chunks, default is 4 - download_chunks=4 # ipinfo.io API key, if applicable ipinfo_api_key="" diff --git a/config/config.go b/config/config.go index 0660ca5..14bcbe4 100644 --- a/config/config.go +++ b/config/config.go @@ -6,10 +6,9 @@ import ( ) type Config struct { - BindAddress string `mapstructure:"bind_address"` - Port string `mapstructure:"listen_port"` - DownloadChunks int `mapstructure:"download_chunks"` - IPInfoAPIKey string `mapstructure:"ipinfo_api_key"` + BindAddress string `mapstructure:"bind_address"` + Port string `mapstructure:"listen_port"` + IPInfoAPIKey string `mapstructure:"ipinfo_api_key"` StatsPassword string `mapstructure:"statistics_password"` RedactIP bool `mapstructure:"redact_ip_addresses"` diff --git a/main.go b/main.go index 42c0ce9..244b099 100644 --- a/main.go +++ b/main.go @@ -11,10 +11,6 @@ import ( func main() { conf := config.Load() - if conf.DownloadChunks > 1024 { - log.Fatal("chunks can't be more than 1024") - } - database.SetDBInfo(&conf) log.Fatal(web.ListenAndServe(&conf)) } diff --git a/settings.toml b/settings.toml index 9f6c91a..89b0436 100644 --- a/settings.toml +++ b/settings.toml @@ -2,8 +2,6 @@ bind_address="" # backend listen port listen_port=8989 -# download test chunks -download_chunks=4 # ipinfo.io API key, if applicable ipinfo_api_key="" diff --git a/web/web.go b/web/web.go index 53c7340..5e625b0 100644 --- a/web/web.go +++ b/web/web.go @@ -91,17 +91,22 @@ func garbage(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Disposition", "attachment; filename=random.dat") w.Header().Set("Content-Transfer-Encoding", "binary") - conf := config.LoadedConfig() - ckSize := r.FormValue("ckSize") + // chunk size set to 4 by default + chunks := 4 - chunks := conf.DownloadChunks + ckSize := r.FormValue("ckSize") if ckSize != "" { i, err := strconv.ParseInt(ckSize, 10, 64) - if err == nil && i > 0 && i < 1024 { - chunks = int(i) - } else { + if err != nil { log.Errorf("Invalid chunk size: %s", ckSize) log.Warn("Will use default value %d", chunks) + } else { + // limit max chunk size to 1024 + if i > 1024 { + chunks = 1024 + } else { + chunks = int(i) + } } }