added the rate limiter - Whoa There, Tiger!
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -35,6 +36,9 @@ const AMSTERDAM_COPYRIGHT = "2025-2026"
|
||||
// CONFIGFILE_NAME is the name of the standard configuration file.
|
||||
const CONFIGFILE_NAME = "amsterdam.yaml"
|
||||
|
||||
// epsilon is used in testing if a float value is 0.
|
||||
const epsilon = 1e-9
|
||||
|
||||
// AmCLI is the command-line interface arguments structure.
|
||||
type AmCLI struct {
|
||||
ConfigFile string `arg:"-C,--config,env:AMSTERDAM_CONFIG" help:"Location of the configuration file."`
|
||||
@@ -90,6 +94,11 @@ type AmConfig struct {
|
||||
WelcomeTitle string `yaml:"welcomeTitle"`
|
||||
WelcomeMessage string `yaml:"welcomeMessage"`
|
||||
TopPostsTitle string `yaml:"topPostsTitle"`
|
||||
RateLimit struct {
|
||||
Rate float64 `yaml:"rate"`
|
||||
Burst int `yaml:"burst"`
|
||||
ExpireMinutes int `yaml:"expireMinutes"`
|
||||
} `yaml:"rateLimit"`
|
||||
} `yaml:"site"`
|
||||
Database struct {
|
||||
Driver string `yaml:"driver"`
|
||||
@@ -278,6 +287,14 @@ func overlayStructValue(dest, loaded, defaults reflect.Value) {
|
||||
} else {
|
||||
fldDest.Set(fldLoaded)
|
||||
}
|
||||
} else if fldDest.CanFloat() {
|
||||
// float field handling
|
||||
n := fldLoaded.Float()
|
||||
if math.Abs(n) <= epsilon {
|
||||
fldDest.Set(fldDefaults)
|
||||
} else {
|
||||
fldDest.Set(fldLoaded)
|
||||
}
|
||||
} else {
|
||||
// if we see this message, this function needs more work
|
||||
log.Errorf("*** unable to deal with field %s of type %s", structField.Name, typ.Name())
|
||||
|
||||
@@ -30,6 +30,10 @@ site:
|
||||
Welcome to the <strong>Amsterdam Web Communities System</strong>. To get the most out of this site, you should log in or create an account,
|
||||
using one of the links above.
|
||||
topPostsTitle: "Latest from the Conferences"
|
||||
rateLimit:
|
||||
rate: 20.0
|
||||
burst: 0
|
||||
expireMinutes: 3
|
||||
database:
|
||||
driver: "mysql"
|
||||
dsn: "amsdb:x00yes2k@tcp(localhost)/amsterdam?parseTime=true&loc=UTC"
|
||||
|
||||
Reference in New Issue
Block a user