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

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

View File

@ -23,29 +23,38 @@ type Clash struct {
} }
func (c *Clash) Get() (proxies []structs.Proxy) { func (c *Clash) Get() (proxies []structs.Proxy) {
var urls = make([]string, 0)
url := c.cfg.Url url := c.cfg.Url
if c.cfg.DateFormat { 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 for _, u := range urls {
resp, err := c.cli.R().Get(url) fmt.Printf("fetching %s\n", u)
if err != nil { var clashConfig clash_config.RawConfig
log.Errorln("get clash config error: %s", err.Error()) resp, err := c.cli.R().Get(u)
return nil if err != nil {
} log.Errorln("get clash config error: %s", err.Error())
err = yaml.Unmarshal(resp.Body(), &clashConfig) return nil
if err != nil { }
log.Errorln("decode clash config error: %s", err.Error()) err = yaml.Unmarshal(resp.Body(), &clashConfig)
return nil if err != nil {
} log.Errorln("decode clash config error: %s", err.Error())
proxies = make([]structs.Proxy, 0, len(clashConfig.Proxy)) return nil
for _, mapping := range clashConfig.Proxy { }
proxy, _ := adapter.ParseProxy(mapping) for _, mapping := range clashConfig.Proxy {
if proxy != nil { proxy, _ := adapter.ParseProxy(mapping)
proxies = append(proxies, structs.NewProxy(proxy, mapping)) if proxy != nil {
proxies = append(proxies, structs.NewProxy(proxy, mapping))
}
} }
} }
return proxies return proxies
} }