FreePad/lib/helper/helper_main.go

75 lines
1.4 KiB
Go
Raw Normal View History

2022-05-19 00:40:34 +03:00
package helper
import (
"os"
"strconv"
)
func GetDomainBase() string {
domainBase, domainExists := os.LookupEnv("DOMAIN_BASE")
if !domainExists {
os.Setenv("DOMAIN_BASE", "http://localhost:8080")
domainBase = "http://localhost:8080"
}
return domainBase
}
2022-05-22 19:38:12 +03:00
func GetApiBanLimit() int {
banLimit, exists := os.LookupEnv("API_BAN_LIMIT")
if !exists {
os.Setenv("API_BAN_LIMIT", "300")
banLimit = "300"
}
// Try and convert the string into an integer
rez, err := strconv.Atoi(banLimit)
// Check if the conversion has failed
if err != nil {
// Simply return the default
return 300
}
return rez
}
func GetMaximumPadSize() int {
// Lookup if the maximum pad size variable exists.
maxPadSize, exists := os.LookupEnv("MAXIMUM_PAD_SIZE")
// Check if this environment variable has bee nset
if !exists {
// Set the variable ourselves to the default string value
maxPadSize = "524288"
}
// Try and convert the string into an integer
rez, err := strconv.Atoi(maxPadSize)
// Check if the conversion has failed
if err != nil {
// Simply return the default
return 524288
}
// Return the resulting value
return rez
}
2022-05-19 00:40:34 +03:00
func GetCacheMapLimit() int {
cacheMapLimit, domainExists := os.LookupEnv("CACHE_MAP_LIMIT")
if !domainExists {
os.Setenv("CACHE_MAP_LIMIT", "25")
cacheMapLimit = "25"
}
rez, err := strconv.Atoi(cacheMapLimit)
if err != nil {
return 25
}
return rez
}