diff --git a/pkg/getter/clash.go b/pkg/getter/clash.go index ae6f364..d9e1013 100644 --- a/pkg/getter/clash.go +++ b/pkg/getter/clash.go @@ -23,29 +23,38 @@ type Clash struct { } func (c *Clash) Get() (proxies []structs.Proxy) { + var urls = make([]string, 0) url := c.cfg.Url if c.cfg.DateFormat { - url = time.Now().Format(url) + now := time.Now() + urls = append(urls, now.Format(url)) + now = now.AddDate(0, 0, -1) + urls = append(urls, now.Format(url)) + } else { + urls = append(urls, url) } - fmt.Printf("fetching %s\n", url) - var clashConfig clash_config.RawConfig - resp, err := c.cli.R().Get(url) - if err != nil { - log.Errorln("get clash config error: %s", err.Error()) - return nil - } - err = yaml.Unmarshal(resp.Body(), &clashConfig) - if err != nil { - log.Errorln("decode clash config error: %s", err.Error()) - return nil - } - proxies = make([]structs.Proxy, 0, len(clashConfig.Proxy)) - for _, mapping := range clashConfig.Proxy { - proxy, _ := adapter.ParseProxy(mapping) - if proxy != nil { - proxies = append(proxies, structs.NewProxy(proxy, mapping)) + + for _, u := range urls { + fmt.Printf("fetching %s\n", u) + var clashConfig clash_config.RawConfig + resp, err := c.cli.R().Get(u) + if err != nil { + log.Errorln("get clash config error: %s", err.Error()) + return nil + } + err = yaml.Unmarshal(resp.Body(), &clashConfig) + if err != nil { + log.Errorln("decode clash config error: %s", err.Error()) + return nil + } + for _, mapping := range clashConfig.Proxy { + proxy, _ := adapter.ParseProxy(mapping) + if proxy != nil { + proxies = append(proxies, structs.NewProxy(proxy, mapping)) + } } } + return proxies }