add limiter config

This commit is contained in:
Yuzuki616
2025-02-18 09:52:48 +09:00
parent f3551df1ca
commit 55f9b28869
3 changed files with 37 additions and 0 deletions

28
common/number/number.go Normal file
View File

@@ -0,0 +1,28 @@
package number
type Number interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~float32 | ~float64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}
func SelectBigger[T Number](num1 T, num2 T) T {
if num1 >= num2 {
return num1
}
return num2
}
func SelectSmaller[T Number](num1 T, num2 T) T {
if num1 <= num2 {
return num1
}
return num2
}
func SelectNotZero[T Number](num1 T, num2 T) T {
if num1 != 0 {
return num1
}
return num1
}

View File

@@ -26,6 +26,7 @@ type Options struct {
Acme string `json:"Acme"`
Cert Cert `json:"Cert"`
Hook Hook `json:"Hook"`
Limit Limit `json:"Limit"`
Expand map[string]interface{} `json:"Other"`
}
@@ -49,6 +50,11 @@ type Hook struct {
AfterDelNode string `json:"AfterDelNode"`
}
type Limit struct {
IPLimit int `json:"IPLimit"`
SpeedLimit uint64 `json:"SpeedLimit"`
}
type Node struct {
Name string `json:"Name"`
Remote Remote `json:"-"`

View File

@@ -5,6 +5,7 @@ import (
"github.com/InazumaV/Ratte-Interface/core"
"github.com/InazumaV/Ratte-Interface/panel"
"github.com/InazumaV/Ratte/common/maps"
"github.com/InazumaV/Ratte/common/number"
)
func (h *Handler) PullNodeHandle(n *panel.NodeInfo) error {
@@ -43,6 +44,8 @@ func (h *Handler) PullNodeHandle(n *panel.NodeInfo) error {
}
ni := (*core.NodeInfo)(n)
ni.OtherOptions = maps.Merge[string, any](ni.OtherOptions, h.Options.Expand)
ni.Limit.IPLimit = number.SelectBigger(ni.Limit.IPLimit, h.Limit.IPLimit)
ni.Limit.SpeedLimit = number.SelectBigger(ni.Limit.SpeedLimit, int(h.Limit.SpeedLimit))
err = h.c.AddNode(&core.AddNodeParams{
NodeInfo: ni,
TlsOptions: core.TlsOptions{