feat 渲染date的话,渲染两天的

This commit is contained in:
timerzz 2024-12-10 11:30:39 +08:00
parent a16cf73fa0
commit f49a976e61

View File

@ -23,13 +23,21 @@ 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)
for _, u := range urls {
fmt.Printf("fetching %s\n", u)
var clashConfig clash_config.RawConfig
resp, err := c.cli.R().Get(url)
resp, err := c.cli.R().Get(u)
if err != nil {
log.Errorln("get clash config error: %s", err.Error())
return nil
@ -39,13 +47,14 @@ func (c *Clash) Get() (proxies []structs.Proxy) {
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))
}
}
}
return proxies
}