ID => SHA256

This commit is contained in:
Michele 2017-01-04 17:40:59 +01:00
parent 36f6aa8a83
commit 8bff28e0dc
4 changed files with 20 additions and 8 deletions

View file

@ -4,6 +4,8 @@ package main
import (
"fmt"
// "github.com/garyburd/redigo/redis"
"crypto/sha256"
"encoding/hex"
"log"
"strconv"
"strings"
@ -19,6 +21,14 @@ type consumed struct {
empty bool
}
func hash(val []byte) string {
h := sha256.New()
h.Write(val)
return hex.EncodeToString(h.Sum(nil))
}
func consumer() {
for {
@ -71,7 +81,7 @@ func consumer() {
}
ml := MongoLogin{
// genera l' _ID con user e timestamp
ID: fmt.Sprintf("%s_%s", prod.user, time.Unix(date, 0).Format("20060102T150405")),
ID: hash([]byte(fmt.Sprintf("%s%s", prod.user, time.Unix(date, 0).Format("20060102T1504")))), // Format("20060102T150405")
User: prod.user,
Protocol: sval[0],
IP: sval[2],

View file

@ -103,8 +103,6 @@ func (c *Counter) addErr(add int) {
// DelWG ...
func (c *Counter) delWG() {
c.mu.Lock()
defer c.mu.Unlock()
c.wg--
}

12
main.go
View file

@ -11,7 +11,7 @@ import (
)
const (
_Version = "v3.1.0"
_Version = "v3.1.1"
_Producer = 0
_Consumer = 1
_Remover = 2
@ -90,16 +90,18 @@ func main() {
count = NewCounter()
consume = make(chan produced)
remove = make(chan consumed)
consume = make(chan produced, opts.Queue)
remove = make(chan consumed, opts.Queue)
loop = true
done = make(chan bool)
counter = make(chan Counterchan)
go count.Run()
go producer()
go consumer()
go remover()
for i := 0; i < opts.Queue; i++ {
go consumer()
go remover()
}
<-done
fmt.Printf("Done\n")

View file

@ -30,6 +30,7 @@ type Options struct {
Hostname string
Month string
Pidfile string
Queue int
}
var (
@ -71,5 +72,6 @@ func init() {
flag.BoolVar(&opts.Debug, "D", false, "Debug")
flag.BoolVar(&opts.Bulk, "B", false, "Bulk")
flag.IntVar(&opts.MaxError, "E", 100, "Max Mongodb Error")
flag.IntVar(&opts.Queue, "q", 2, "parallel consumer")
flag.StringVar(&opts.Pidfile, "p", opts.Pidfile, "pid file")
}