Skip to content

Instantly share code, notes, and snippets.

@catatsuy
Created September 23, 2015 08:55
Show Gist options
  • Save catatsuy/f4b30b1c6a5e141cde12 to your computer and use it in GitHub Desktop.
Save catatsuy/f4b30b1c6a5e141cde12 to your computer and use it in GitHub Desktop.
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