From 81c832ef9ef97265da9e59298b3642554ca17fe7 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Tue, 12 Mar 2024 15:14:56 +0800 Subject: [PATCH] chore: code cleanup --- adapter/provider/provider.go | 14 ++------------ common/utils/ranges.go | 6 +++++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index b1209d224a..2715a30972 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -46,18 +46,13 @@ type proxySetProvider struct { } func (pp *proxySetProvider) MarshalJSON() ([]byte, error) { - expectedStatus := "*" - if pp.healthCheck.expectedStatus != nil { - expectedStatus = pp.healthCheck.expectedStatus.ToString() - } - return json.Marshal(map[string]any{ "name": pp.Name(), "type": pp.Type().String(), "vehicleType": pp.VehicleType().String(), "proxies": pp.Proxies(), "testUrl": pp.healthCheck.url, - "expectedStatus": expectedStatus, + "expectedStatus": pp.healthCheck.expectedStatus.String(), "updatedAt": pp.UpdatedAt, "subscriptionInfo": pp.subscriptionInfo, }) @@ -221,18 +216,13 @@ type compatibleProvider struct { } func (cp *compatibleProvider) MarshalJSON() ([]byte, error) { - expectedStatus := "*" - if cp.healthCheck.expectedStatus != nil { - expectedStatus = cp.healthCheck.expectedStatus.ToString() - } - return json.Marshal(map[string]any{ "name": cp.Name(), "type": cp.Type().String(), "vehicleType": cp.VehicleType().String(), "proxies": cp.Proxies(), "testUrl": cp.healthCheck.url, - "expectedStatus": expectedStatus, + "expectedStatus": cp.healthCheck.expectedStatus.String(), }) } diff --git a/common/utils/ranges.go b/common/utils/ranges.go index e656e34b3c..c71f84c9d5 100644 --- a/common/utils/ranges.go +++ b/common/utils/ranges.go @@ -110,7 +110,7 @@ func (ranges IntRanges[T]) Check(status T) bool { return false } -func (ranges IntRanges[T]) ToString() string { +func (ranges IntRanges[T]) String() string { if len(ranges) == 0 { return "*" } @@ -134,6 +134,10 @@ func (ranges IntRanges[T]) ToString() string { } func (ranges IntRanges[T]) Range(f func(t T) bool) { + if len(ranges) == 0 { + return + } + for _, r := range ranges { for i := r.Start(); i <= r.End(); i++ { if !f(i) {