Browse Source

update: `disable` option for asset

v1.x.x
dnomd343 2 years ago
parent
commit
c9b917663b
  1. 17
      cmd/asset/update.go
  2. 17
      cmd/config/decode.go
  3. 11
      cmd/config/default.go
  4. 2
      cmd/config/main.go
  5. 16
      cmd/controller.go

17
cmd/asset/update.go

@ -8,9 +8,12 @@ import (
) )
type Config struct { type Config struct {
Proxy string `yaml:"proxy" json:"proxy"` Disable bool `yaml:"disable" json:"disable"`
Cron string `yaml:"cron" json:"cron"` Update struct {
Url map[string]string `yaml:"url" json:"url"` Proxy string `yaml:"proxy" json:"proxy"`
Cron string `yaml:"cron" json:"cron"`
Url map[string]string `yaml:"url" json:"url"`
}
} }
func updateAsset(urls map[string]string, assetDir string, updateProxy string) { // download new assets func updateAsset(urls map[string]string, assetDir string, updateProxy string) { // download new assets
@ -27,11 +30,11 @@ func updateAsset(urls map[string]string, assetDir string, updateProxy string) {
} }
} }
func AutoUpdate(update *Config, assetDir string) { // set cron task for auto update func AutoUpdate(config *Config, assetDir string) { // set cron task for auto update
if update.Cron != "" { if config.Update.Cron != "" {
autoUpdate := cron.New() autoUpdate := cron.New()
_ = autoUpdate.AddFunc(update.Cron, func() { // cron function _ = autoUpdate.AddFunc(config.Update.Cron, func() { // cron function
updateAsset(update.Url, assetDir, update.Proxy) updateAsset(config.Update.Url, assetDir, config.Update.Proxy)
}) })
autoUpdate.Start() autoUpdate.Start()
} }

17
cmd/config/decode.go

@ -18,7 +18,7 @@ type NetConfig struct {
} }
type RawConfig struct { type RawConfig struct {
Update asset.Config `yaml:"update" json:"update"` Asset asset.Config `yaml:"asset" json:"asset"`
Radvd radvd.Config `yaml:"radvd" json:"radvd"` Radvd radvd.Config `yaml:"radvd" json:"radvd"`
Proxy proxy.Config `yaml:"proxy" json:"proxy"` Proxy proxy.Config `yaml:"proxy" json:"proxy"`
Custom custom.Config `yaml:"custom" json:"custom"` Custom custom.Config `yaml:"custom" json:"custom"`
@ -164,16 +164,17 @@ func decodeRadvd(rawConfig *RawConfig, config *Config) {
} }
func decodeUpdate(rawConfig *RawConfig, config *Config) { func decodeUpdate(rawConfig *RawConfig, config *Config) {
config.Update = rawConfig.Update config.Asset = rawConfig.Asset
if config.Update.Proxy != "" { if config.Asset.Update.Proxy != "" {
_, err := url.Parse(config.Update.Proxy) // check proxy info _, err := url.Parse(config.Asset.Update.Proxy) // check proxy info
if err != nil { if err != nil {
log.Panicf("Invalid update proxy -> %s", config.Update.Proxy) log.Panicf("Invalid asset update proxy -> %s", config.Asset.Update.Proxy)
} }
} }
log.Debugf("Update proxy -> %s", config.Update.Proxy) log.Debugf("Asset disable -> %t", config.Asset.Disable)
log.Debugf("Update cron -> %s", config.Update.Cron) log.Debugf("Asset update proxy -> %s", config.Asset.Update.Proxy)
log.Debugf("Update urls -> %v", config.Update.Url) log.Debugf("Asset update cron -> %s", config.Asset.Update.Cron)
log.Debugf("Asset update urls -> %v", config.Asset.Update.Url)
} }
func decodeCustom(rawConfig *RawConfig, config *Config) { func decodeCustom(rawConfig *RawConfig, config *Config) {

11
cmd/config/default.go

@ -13,9 +13,10 @@ network:
- fe80::/10 - fe80::/10
- ff00::/8 - ff00::/8
update: asset:
cron: "0 0 4 * * *" update:
url: cron: "0 0 4 * * *"
geoip.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat" url:
geosite.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat" geoip.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat"
geosite.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
` `

2
cmd/config/main.go

@ -18,7 +18,7 @@ type Config struct {
IPv4 network.Config IPv4 network.Config
IPv6 network.Config IPv6 network.Config
Proxy proxy.Config Proxy proxy.Config
Update asset.Config Asset asset.Config
Radvd radvd.Config Radvd radvd.Config
Custom custom.Config Custom custom.Config
} }

16
cmd/controller.go

@ -29,12 +29,20 @@ func blockWait() {
} }
func loadRadvd(settings *config.Config) { func loadRadvd(settings *config.Config) {
radvd.Load(&settings.Radvd) if settings.Radvd.Enable {
radvd.Load(&settings.Radvd)
} else {
log.Infof("Skip loading radvd")
}
} }
func loadAsset(settings *config.Config) { func loadAsset(settings *config.Config) {
asset.Load(assetFile, assetDir) if settings.Asset.Disable {
asset.AutoUpdate(&settings.Update, assetDir) log.Infof("Skip loading asset")
} else {
asset.Load(assetFile, assetDir)
asset.AutoUpdate(&settings.Asset, assetDir)
}
} }
func loadNetwork(settings *config.Config) { func loadNetwork(settings *config.Config) {
@ -72,5 +80,7 @@ func runRadvd(settings *config.Config) {
radvdCmd = append(radvdCmd, "--debug", strconv.Itoa(settings.Radvd.Log)) radvdCmd = append(radvdCmd, "--debug", strconv.Itoa(settings.Radvd.Log))
} }
runProcess(nil, radvdCmd...) runProcess(nil, radvdCmd...)
} else {
log.Infof("Skip running radvd")
} }
} }

Loading…
Cancel
Save