mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 18:08:14 -05:00
15c36a9580
refactor limiter fix getLink bug add connection limit move limit config to ControllerConfig del dynamic speed limit (next version will be re add) del online ip sync (next version will be re add)
41 lines
857 B
Go
41 lines
857 B
Go
package iprecoder
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/Yuzuki616/V2bX/conf"
|
|
"github.com/Yuzuki616/V2bX/limiter"
|
|
"github.com/go-resty/resty/v2"
|
|
"github.com/goccy/go-json"
|
|
"time"
|
|
)
|
|
|
|
type Recorder struct {
|
|
client *resty.Client
|
|
*conf.RecorderConfig
|
|
}
|
|
|
|
func NewRecorder(c *conf.RecorderConfig) *Recorder {
|
|
return &Recorder{
|
|
client: resty.New().SetTimeout(time.Duration(c.Timeout) * time.Second),
|
|
RecorderConfig: c,
|
|
}
|
|
}
|
|
|
|
func (r *Recorder) SyncOnlineIp(ips []limiter.UserIpList) ([]limiter.UserIpList, error) {
|
|
rsp, err := r.client.R().
|
|
SetBody(ips).
|
|
Post(r.Url + "/api/v1/SyncOnlineIp?token=" + r.Token)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if rsp.StatusCode() != 200 {
|
|
return nil, errors.New(rsp.String())
|
|
}
|
|
ips = []limiter.UserIpList{}
|
|
err = json.Unmarshal(rsp.Body(), &ips)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ips, nil
|
|
}
|