|  | @@ -2,11 +2,8 @@ package main
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import (
 | 
	
		
			
				|  |  |  	"bufio"
 | 
	
		
			
				|  |  | -	"crypto/sha256"
 | 
	
		
			
				|  |  | -	"encoding/hex"
 | 
	
		
			
				|  |  |  	"encoding/json"
 | 
	
		
			
				|  |  |  	"fmt"
 | 
	
		
			
				|  |  | -	"io"
 | 
	
		
			
				|  |  |  	"io/ioutil"
 | 
	
		
			
				|  |  |  	"log"
 | 
	
		
			
				|  |  |  	"os"
 | 
	
	
		
			
				|  | @@ -75,26 +72,12 @@ func main() {
 | 
	
		
			
				|  |  |  			saveAllHashFiles()
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	} else {
 | 
	
		
			
				|  |  | -		log.Printf("file %s has hash %s\n", myFile, getSha256Hash(myFile))
 | 
	
		
			
				|  |  | +		log.Printf("file %s has hash %s\n", myFile, hash.GetFileHash(myFile))
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	log.Println("done")
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func getSha256Hash(fileStr string) string {
 | 
	
		
			
				|  |  | -	f, err := os.Open(fileStr)
 | 
	
		
			
				|  |  | -	if err != nil {
 | 
	
		
			
				|  |  | -		log.Fatal(err)
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	defer f.Close()
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	h := sha256.New()
 | 
	
		
			
				|  |  | -	if _, err := io.Copy(h, f); err != nil {
 | 
	
		
			
				|  |  | -		log.Fatal(err)
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	return hex.EncodeToString(h.Sum(nil))
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  var lock1 = sync.RWMutex{}
 | 
	
		
			
				|  |  |  var lock2 = sync.RWMutex{}
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -135,7 +118,7 @@ func calculateHash(fileStr string) {
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	if doHash {
 | 
	
		
			
				|  |  |  		log.Printf("starting %s\n", fileStr)
 | 
	
		
			
				|  |  | -		hash := getSha256Hash(fileStr)
 | 
	
		
			
				|  |  | +		hash := hash.GetFileHash(fileStr)
 | 
	
		
			
				|  |  |  		log.Printf("ready %s\n", fileStr)
 | 
	
		
			
				|  |  |  		mu.Lock()
 | 
	
		
			
				|  |  |  		lock1.Lock()
 |