package router import ( "strings" "time" "go.jolheiser.com/vanity/flags" "go.jolheiser.com/vanity/service" "go.jolheiser.com/beaver" ) var svc service.Service func cronStart() { ticker := time.NewTicker(flags.Interval) for { <-ticker.C beaver.Debug("Running package update...") cronUpdate() beaver.Debugf("Finished package update: %s", cache.Names()) } } func cronUpdate() { packages, err := svc.Packages() if err != nil { beaver.Errorf("could not update packages: %v", err) return } // Filter for name, pkg := range packages { if err := service.Check(pkg); err != nil { beaver.Debug(err) delete(packages, name) continue } goMod, err := svc.GoMod(pkg) if err != nil { beaver.Debugf("No go.mod could be found in the root directory of %s", pkg.Name) delete(packages, name) continue } lines := strings.Split(goMod, "\n") line := strings.Fields(lines[0]) if !strings.HasPrefix(line[1], flags.Domain) { beaver.Debugf("%s is a Go project, however its module does not include this domain", pkg.Name) delete(packages, name) continue } beaver.Debugf("Including %s", pkg.Name) } // Overrides for name, pkg := range packages { for key, override := range flags.Override { if strings.EqualFold(name, key) { beaver.Debugf("Overriding %s -> %s", name, override) delete(packages, key) pkg.Name = override packages[override] = pkg } } } // Add packages manually added to config for _, pkg := range flags.ConfigPackages { packages[pkg.Name] = pkg } cache.Update(packages) }