github.com/metacubex/mihomo@v1.18.5/adapter/provider/subscription_info.go (about) 1 package provider 2 3 import ( 4 "strconv" 5 "strings" 6 ) 7 8 type SubscriptionInfo struct { 9 Upload int64 10 Download int64 11 Total int64 12 Expire int64 13 } 14 15 func NewSubscriptionInfo(userinfo string) (si *SubscriptionInfo, err error) { 16 userinfo = strings.ToLower(userinfo) 17 userinfo = strings.ReplaceAll(userinfo, " ", "") 18 si = new(SubscriptionInfo) 19 for _, field := range strings.Split(userinfo, ";") { 20 switch name, value, _ := strings.Cut(field, "="); name { 21 case "upload": 22 si.Upload, err = strconv.ParseInt(value, 10, 64) 23 case "download": 24 si.Download, err = strconv.ParseInt(value, 10, 64) 25 case "total": 26 si.Total, err = strconv.ParseInt(value, 10, 64) 27 case "expire": 28 if value == "" { 29 si.Expire = 0 30 } else { 31 si.Expire, err = strconv.ParseInt(value, 10, 64) 32 } 33 } 34 if err != nil { 35 return 36 } 37 } 38 return 39 }