mirror of
https://github.com/InazumaV/Ratte.git
synced 2026-02-03 20:20:14 +00:00
add limiter config
This commit is contained in:
28
common/number/number.go
Normal file
28
common/number/number.go
Normal 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
|
||||
}
|
||||
@@ -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:"-"`
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user