diff --git a/main.go b/main.go index d45dd6e..fb2677a 100644 --- a/main.go +++ b/main.go @@ -42,8 +42,7 @@ func main() { go GetSyncFilesRecursively(dir, files, status) - typeByExtension := sync.Map{} - countByExtension := sync.Map{} + extensionTypeCount := sync.Map{} wg := sync.WaitGroup{} for file := range files { wg.Add(1) @@ -58,15 +57,17 @@ func main() { scanner := bufio.NewScanner(f) if scanner.Scan() { ext := filepath.Ext(file) - count, _ := countByExtension.LoadOrStore(ext, 0) + key := ext if IsStringBinary(scanner.Text()) { - log.Printf("Binary file: %s (%s)", file, ext) - typeByExtension.Store(ext, "binary") - countByExtension.Store(ext, count.(int)+1) + key += " (binary)" + count, _ := extensionTypeCount.LoadOrStore(key, 0) + extensionTypeCount.Store(key, count.(int)+1) + //log.Printf("Binary file: %s (%s)", file, ext) } else { - log.Printf("Text file: %s (%s)", file, ext) - typeByExtension.Store(ext, "text") - countByExtension.Store(ext, count.(int)+1) + key += " (text)" + count, _ := extensionTypeCount.LoadOrStore(key, 0) + extensionTypeCount.Store(key, count.(int)+1) + //log.Printf("Text file: %s (%s)", file, ext) } } else if err := scanner.Err(); err != nil { log.Printf("Error reading line from file %s: %v", file, err) @@ -77,12 +78,8 @@ func main() { } wg.Wait() - countByExtension.Range(func(key, value any) bool { - typ, ok := typeByExtension.Load(key) - if !ok { - typ = "unknown" - } - log.Printf("Extension: %s, Type: %s, Count: %d", key, typ, value.(int)) + extensionTypeCount.Range(func(key, value any) bool { + log.Printf("Extension: %s, Count: %d", key, value.(int)) return true }) }