From f49a976e61f3748f0166a2e34d540a3ba5b08028 Mon Sep 17 00:00:00 2001 From: timerzz Date: Tue, 10 Dec 2024 11:30:39 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B8=B2=E6=9F=93date=E7=9A=84=E8=AF=9D?= =?UTF-8?q?=EF=BC=8C=E6=B8=B2=E6=9F=93=E4=B8=A4=E5=A4=A9=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/getter/clash.go | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) 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 }