mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-01-12 10:09:00 +08:00
chore: moving rules disabled and hit/miss counts data to extra for restful api (#2503)
This commit is contained in:
parent
c8e33a4347
commit
ae6069c178
@ -27,12 +27,16 @@ type Rule struct {
|
||||
Proxy string `json:"proxy"`
|
||||
Size int `json:"size"`
|
||||
|
||||
// from RuleWrapper
|
||||
Disabled bool `json:"disabled,omitempty"`
|
||||
HitCount uint64 `json:"hitCount,omitempty"`
|
||||
HitAt time.Time `json:"hitAt,omitempty"`
|
||||
MissCount uint64 `json:"missCount,omitempty"`
|
||||
MissAt time.Time `json:"missAt,omitempty"`
|
||||
// Extra contains information from RuleWrapper
|
||||
Extra *RuleExtra `json:"extra,omitempty"`
|
||||
}
|
||||
|
||||
type RuleExtra struct {
|
||||
Disabled bool `json:"disabled"`
|
||||
HitCount uint64 `json:"hitCount"`
|
||||
HitAt time.Time `json:"hitAt"`
|
||||
MissCount uint64 `json:"missCount"`
|
||||
MissAt time.Time `json:"missAt"`
|
||||
}
|
||||
|
||||
func getRules(w http.ResponseWriter, r *http.Request) {
|
||||
@ -47,11 +51,13 @@ func getRules(w http.ResponseWriter, r *http.Request) {
|
||||
Size: -1,
|
||||
}
|
||||
if ruleWrapper, ok := rule.(constant.RuleWrapper); ok {
|
||||
r.Disabled = ruleWrapper.IsDisabled()
|
||||
r.HitCount = ruleWrapper.HitCount()
|
||||
r.HitAt = ruleWrapper.HitAt()
|
||||
r.MissCount = ruleWrapper.MissCount()
|
||||
r.MissAt = ruleWrapper.MissAt()
|
||||
r.Extra = &RuleExtra{
|
||||
Disabled: ruleWrapper.IsDisabled(),
|
||||
HitCount: ruleWrapper.HitCount(),
|
||||
HitAt: ruleWrapper.HitAt(),
|
||||
MissCount: ruleWrapper.MissCount(),
|
||||
MissAt: ruleWrapper.MissAt(),
|
||||
}
|
||||
rule = ruleWrapper.Unwrap() // unwrap RuleWrapper
|
||||
}
|
||||
if rule.RuleType() == constant.GEOIP || rule.RuleType() == constant.GEOSITE {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user