Created
September 23, 2015 08:55
-
-
Save catatsuy/f4b30b1c6a5e141cde12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"crypto/md5" | |
"fmt" | |
"os" | |
"time" | |
goCache "github.com/pmylund/go-cache" | |
) | |
func main() { | |
fp, err := os.Open(os.Args[1]) | |
if err != nil { | |
panic(err) | |
} | |
defer fp.Close() | |
c := goCache.New(5*time.Minute, 30*time.Second) | |
var key string | |
scanner := bufio.NewScanner(fp) | |
for scanner.Scan() { | |
key = fmt.Sprintf("%x", md5.Sum(scanner.Bytes()))[0:12] | |
value, found := c.Get(key) | |
if found { | |
fmt.Println(value, key, scanner.Text()) | |
} else { | |
c.Set(fmt.Sprintf("%x", md5.Sum(scanner.Bytes()))[0:12], scanner.Text(), -1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment