diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index 8558c434..64d83b08 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -137,7 +137,7 @@ func (pp *proxySetProvider) Initial() error { return err } if subscriptionInfo := cachefile.Cache().GetSubscriptionInfo(pp.Name()); subscriptionInfo != "" { - pp.subscriptionInfo.Update(subscriptionInfo) + pp.subscriptionInfo = NewSubscriptionInfo(subscriptionInfo) } pp.closeAllConnections() return nil @@ -165,14 +165,12 @@ func NewProxySetProvider(name string, interval time.Duration, parser resource.Pa go hc.process() } - si := new(SubscriptionInfo) pd := &proxySetProvider{ baseProvider: baseProvider{ name: name, proxies: []C.Proxy{}, healthCheck: hc, }, - subscriptionInfo: si, } fetcher := resource.NewFetcher[[]C.Proxy](name, interval, vehicle, parser, proxiesOnUpdate(pd)) @@ -181,7 +179,7 @@ func NewProxySetProvider(name string, interval time.Duration, parser resource.Pa httpVehicle.SetInRead(func(resp *http.Response) { if subscriptionInfo := resp.Header.Get("subscription-userinfo"); subscriptionInfo != "" { cachefile.Cache().SetSubscriptionInfo(name, subscriptionInfo) - si.Update(subscriptionInfo) + pd.subscriptionInfo = NewSubscriptionInfo(subscriptionInfo) } }) } diff --git a/adapter/provider/subscription_info.go b/adapter/provider/subscription_info.go index 194e3984..2ec8537d 100644 --- a/adapter/provider/subscription_info.go +++ b/adapter/provider/subscription_info.go @@ -15,8 +15,9 @@ type SubscriptionInfo struct { Expire int64 } -func (info *SubscriptionInfo) Update(userinfo string) { +func NewSubscriptionInfo(userinfo string) (si *SubscriptionInfo) { userinfo = strings.ReplaceAll(strings.ToLower(userinfo), " ", "") + si = new(SubscriptionInfo) for _, field := range strings.Split(userinfo, ";") { name, value, ok := strings.Cut(field, "=") @@ -32,15 +33,16 @@ func (info *SubscriptionInfo) Update(userinfo string) { switch name { case "upload": - info.Upload = intValue + si.Upload = intValue case "download": - info.Download = intValue + si.Download = intValue case "total": - info.Total = intValue + si.Total = intValue case "expire": - info.Expire = intValue + si.Expire = intValue } } + return si } func parseValue(value string) (int64, error) {