mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 12:40:11 +00:00
refactor ipRecorder
This commit is contained in:
7
api/iprecoder/interface.go
Normal file
7
api/iprecoder/interface.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package iprecoder
|
||||
|
||||
import "github.com/Yuzuki616/V2bX/core/app/dispatcher"
|
||||
|
||||
type IpRecorder interface {
|
||||
SyncOnlineIp(Ips []dispatcher.UserIpList) ([]dispatcher.UserIpList, error)
|
||||
}
|
||||
40
api/iprecoder/recorder.go
Normal file
40
api/iprecoder/recorder.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package iprecoder
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/Yuzuki616/V2bX/core/app/dispatcher"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/goccy/go-json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Recorder struct {
|
||||
client *resty.Client
|
||||
*conf.RecorderConfig
|
||||
}
|
||||
|
||||
func New(c *conf.RecorderConfig) *Recorder {
|
||||
return &Recorder{
|
||||
client: resty.New().SetTimeout(time.Duration(c.Timeout) * time.Second),
|
||||
RecorderConfig: c,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Recorder) SyncOnlineIp(ips []dispatcher.UserIpList) ([]dispatcher.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 = []dispatcher.UserIpList{}
|
||||
err = json.Unmarshal(rsp.Body(), &ips)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ips, nil
|
||||
}
|
||||
1
api/iprecoder/redis.go
Normal file
1
api/iprecoder/redis.go
Normal file
@@ -0,0 +1 @@
|
||||
package iprecoder
|
||||
Reference in New Issue
Block a user