Remove chunk size setting
Conforms with the PHP backend behavior
This commit is contained in:
parent
62b8a3c17f
commit
96ea2ede4c
|
@ -68,8 +68,6 @@ You need Go 1.13+ to compile the binary.
|
||||||
bind_address="127.0.0.1"
|
bind_address="127.0.0.1"
|
||||||
# backend listen port, default is 8989
|
# backend listen port, default is 8989
|
||||||
listen_port=8989
|
listen_port=8989
|
||||||
# download test chunks, default is 4
|
|
||||||
download_chunks=4
|
|
||||||
# ipinfo.io API key, if applicable
|
# ipinfo.io API key, if applicable
|
||||||
ipinfo_api_key=""
|
ipinfo_api_key=""
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
BindAddress string `mapstructure:"bind_address"`
|
BindAddress string `mapstructure:"bind_address"`
|
||||||
Port string `mapstructure:"listen_port"`
|
Port string `mapstructure:"listen_port"`
|
||||||
DownloadChunks int `mapstructure:"download_chunks"`
|
IPInfoAPIKey string `mapstructure:"ipinfo_api_key"`
|
||||||
IPInfoAPIKey string `mapstructure:"ipinfo_api_key"`
|
|
||||||
|
|
||||||
StatsPassword string `mapstructure:"statistics_password"`
|
StatsPassword string `mapstructure:"statistics_password"`
|
||||||
RedactIP bool `mapstructure:"redact_ip_addresses"`
|
RedactIP bool `mapstructure:"redact_ip_addresses"`
|
||||||
|
|
4
main.go
4
main.go
|
@ -11,10 +11,6 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
conf := config.Load()
|
conf := config.Load()
|
||||||
|
|
||||||
if conf.DownloadChunks > 1024 {
|
|
||||||
log.Fatal("chunks can't be more than 1024")
|
|
||||||
}
|
|
||||||
|
|
||||||
database.SetDBInfo(&conf)
|
database.SetDBInfo(&conf)
|
||||||
log.Fatal(web.ListenAndServe(&conf))
|
log.Fatal(web.ListenAndServe(&conf))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
bind_address=""
|
bind_address=""
|
||||||
# backend listen port
|
# backend listen port
|
||||||
listen_port=8989
|
listen_port=8989
|
||||||
# download test chunks
|
|
||||||
download_chunks=4
|
|
||||||
# ipinfo.io API key, if applicable
|
# ipinfo.io API key, if applicable
|
||||||
ipinfo_api_key=""
|
ipinfo_api_key=""
|
||||||
|
|
||||||
|
|
17
web/web.go
17
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-Disposition", "attachment; filename=random.dat")
|
||||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||||
|
|
||||||
conf := config.LoadedConfig()
|
// chunk size set to 4 by default
|
||||||
ckSize := r.FormValue("ckSize")
|
chunks := 4
|
||||||
|
|
||||||
chunks := conf.DownloadChunks
|
ckSize := r.FormValue("ckSize")
|
||||||
if ckSize != "" {
|
if ckSize != "" {
|
||||||
i, err := strconv.ParseInt(ckSize, 10, 64)
|
i, err := strconv.ParseInt(ckSize, 10, 64)
|
||||||
if err == nil && i > 0 && i < 1024 {
|
if err != nil {
|
||||||
chunks = int(i)
|
|
||||||
} else {
|
|
||||||
log.Errorf("Invalid chunk size: %s", ckSize)
|
log.Errorf("Invalid chunk size: %s", ckSize)
|
||||||
log.Warn("Will use default value %d", chunks)
|
log.Warn("Will use default value %d", chunks)
|
||||||
|
} else {
|
||||||
|
// limit max chunk size to 1024
|
||||||
|
if i > 1024 {
|
||||||
|
chunks = 1024
|
||||||
|
} else {
|
||||||
|
chunks = int(i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue