Skip to content

Commit

Permalink
adding some logs
Browse files Browse the repository at this point in the history
Signed-off-by: Raj Babu Das <[email protected]>
  • Loading branch information
imrajdas committed Aug 26, 2023
1 parent 40d5e82 commit b5e5ee2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ var VersionCmd = &cobra.Command{
Short: "Displays the version of diffr",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
cmd.Printf("Diffr Version: %s", os.Getenv("VERSION"))
version := os.Getenv("VERSION")
if version == "" {
version = "develop"
}

cmd.Printf("Diffr Version: %s", version)
},
}
5 changes: 5 additions & 0 deletions pkg/diffr/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func compareFiles(file1, file2 string) (string, error) {
func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan chan<- error, wg *sync.WaitGroup) {
defer wg.Done()

var comparisonsCount int
filepath.Walk(dir1, func(path1 string, info os.FileInfo, err error) error {
if err != nil {
errorChan <- fmt.Errorf("error accessing %s: %s", path1, err)
Expand All @@ -91,6 +92,7 @@ func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan cha
}

if diff != "" {
comparisonsCount++
diffChan <- fmt.Sprintf("Differences in file: %s\n%s", relPath, diff)
}
} else if os.IsNotExist(err) {
Expand All @@ -108,6 +110,7 @@ func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan cha
}

if diff != "" {
comparisonsCount++
diffChan <- fmt.Sprintf("Differences in file: %s (present in %s but not in %s)\n%s", relPath, dir1, dir2, diff)
}
} else {
Expand All @@ -116,4 +119,6 @@ func CompareDirectories(dir1, dir2 string, diffChan chan<- string, errorChan cha

return nil
})

fmt.Printf("Total file comparisons: %d\n", comparisonsCount) // Print the count at the end
}
6 changes: 6 additions & 0 deletions pkg/diffr/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime"
"sync"
"syscall"
"time"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -92,11 +93,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
finalStr = ""
diffChan = make(chan string)
errorChan = make(chan error)
start = time.Now()
elapsed time.Duration
)

go func() {
for diff := range diffChan {
finalStr += diff
elapsed = time.Since(start)
}
}()

Expand All @@ -113,6 +117,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
close(diffChan)
close(errorChan)

fmt.Printf("Time taken to analyze all files: %s\n", elapsed)

tmpl, err := template.ParseFiles("static/templates/template.html")
if err != nil {
fmt.Printf("error: %v", err)
Expand Down

0 comments on commit b5e5ee2

Please sign in to comment.