Clean up code reuse, consistency, and efficiency issues

Merge readExistingSerial and readExistingContent into a single
readExisting function to eliminate duplicate file I/O. Extract dateBase
helper to deduplicate serial formula between defaultSerial and
bumpSerial. Cache hash results during collision check to avoid
recomputing per member. Normalize error prefixes (remove "error:" from
fmt.Errorf, add uniformly at print sites). Use filepath.Join instead of
manual "/" concatenation. Replace trivial containsStr wrapper with
strings.Contains. Simplify tokenize to a single return. Use writeTestFile
and fixedTime helpers consistently in tests.
This commit is contained in:
2026-03-01 17:38:26 -08:00
parent 1f2f39f40c
commit 0a460b975d
7 changed files with 75 additions and 117 deletions

10
main.go
View File

@@ -41,7 +41,7 @@ func main() {
members, err := parseInput(inputFile, cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
@@ -58,15 +58,15 @@ func main() {
for _, catName := range catNames {
changed, err := processCatalog(catName, cfg, members[catName], *outputDir, now)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
fmt.Fprintf(os.Stderr, "error: %s\n", err)
hasErrors = true
continue
}
catZone := cfg.Catalogs[catName].Zone
zoneFile := cfg.Catalogs[catName].Zone + "zone"
if changed {
fmt.Fprintf(os.Stderr, "%s%s: updated\n", catZone, "zone")
fmt.Fprintf(os.Stderr, "%s: updated\n", zoneFile)
} else {
fmt.Fprintf(os.Stderr, "%s%s: unchanged\n", catZone, "zone")
fmt.Fprintf(os.Stderr, "%s: unchanged\n", zoneFile)
}
}