changed rate limit to environment variable
This commit is contained in:
parent
5228a9be38
commit
d528bc987e
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -33,6 +34,8 @@ func main() {
|
||||||
dbUser := os.Getenv("DB_USER")
|
dbUser := os.Getenv("DB_USER")
|
||||||
dbPass := os.Getenv("DB_PASS")
|
dbPass := os.Getenv("DB_PASS")
|
||||||
discordToken := os.Getenv("DISCORD_TOKEN")
|
discordToken := os.Getenv("DISCORD_TOKEN")
|
||||||
|
rateLimit := os.Getenv("RATE_LIMIT")
|
||||||
|
timeLimit := os.Getenv("TIME_LIMIT")
|
||||||
dsn := fmt.Sprintf("%s:%s@tcp(db:3306)/badwords?parseTime=true", dbUser, dbPass)
|
dsn := fmt.Sprintf("%s:%s@tcp(db:3306)/badwords?parseTime=true", dbUser, dbPass)
|
||||||
infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime)
|
infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime)
|
||||||
errorLog := log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile)
|
errorLog := log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile)
|
||||||
|
@ -42,9 +45,19 @@ func main() {
|
||||||
errorLog.Fatal(err)
|
errorLog.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rateLim, err := strconv.Atoi(rateLimit)
|
||||||
|
if err != nil {
|
||||||
|
errorLog.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
timeLim, err := strconv.Atoi(timeLimit)
|
||||||
|
if err != nil {
|
||||||
|
errorLog.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
limiter := &limiter.Limiter{
|
limiter := &limiter.Limiter{
|
||||||
RateLimit: 5,
|
RateLimit: rateLim,
|
||||||
TimeLimit: time.Second * 15,
|
TimeLimit: time.Duration(timeLim * int(time.Second)),
|
||||||
Logs: make(map[string][]*limiter.Action),
|
Logs: make(map[string][]*limiter.Action),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue