ID => SHA256
This commit is contained in:
parent
36f6aa8a83
commit
8bff28e0dc
4 changed files with 20 additions and 8 deletions
12
consumer.go
12
consumer.go
|
@ -4,6 +4,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
// "github.com/garyburd/redigo/redis"
|
// "github.com/garyburd/redigo/redis"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -19,6 +21,14 @@ type consumed struct {
|
||||||
empty bool
|
empty bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hash(val []byte) string {
|
||||||
|
|
||||||
|
h := sha256.New()
|
||||||
|
h.Write(val)
|
||||||
|
|
||||||
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
|
}
|
||||||
|
|
||||||
func consumer() {
|
func consumer() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -71,7 +81,7 @@ func consumer() {
|
||||||
}
|
}
|
||||||
ml := MongoLogin{
|
ml := MongoLogin{
|
||||||
// genera l' _ID con user e timestamp
|
// 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,
|
User: prod.user,
|
||||||
Protocol: sval[0],
|
Protocol: sval[0],
|
||||||
IP: sval[2],
|
IP: sval[2],
|
||||||
|
|
|
@ -103,8 +103,6 @@ func (c *Counter) addErr(add int) {
|
||||||
|
|
||||||
// DelWG ...
|
// DelWG ...
|
||||||
func (c *Counter) delWG() {
|
func (c *Counter) delWG() {
|
||||||
c.mu.Lock()
|
|
||||||
defer c.mu.Unlock()
|
|
||||||
c.wg--
|
c.wg--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
main.go
12
main.go
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
_Version = "v3.1.0"
|
_Version = "v3.1.1"
|
||||||
_Producer = 0
|
_Producer = 0
|
||||||
_Consumer = 1
|
_Consumer = 1
|
||||||
_Remover = 2
|
_Remover = 2
|
||||||
|
@ -90,16 +90,18 @@ func main() {
|
||||||
|
|
||||||
count = NewCounter()
|
count = NewCounter()
|
||||||
|
|
||||||
consume = make(chan produced)
|
consume = make(chan produced, opts.Queue)
|
||||||
remove = make(chan consumed)
|
remove = make(chan consumed, opts.Queue)
|
||||||
loop = true
|
loop = true
|
||||||
done = make(chan bool)
|
done = make(chan bool)
|
||||||
counter = make(chan Counterchan)
|
counter = make(chan Counterchan)
|
||||||
|
|
||||||
go count.Run()
|
go count.Run()
|
||||||
go producer()
|
go producer()
|
||||||
go consumer()
|
for i := 0; i < opts.Queue; i++ {
|
||||||
go remover()
|
go consumer()
|
||||||
|
go remover()
|
||||||
|
}
|
||||||
|
|
||||||
<-done
|
<-done
|
||||||
fmt.Printf("Done\n")
|
fmt.Printf("Done\n")
|
||||||
|
|
|
@ -30,6 +30,7 @@ type Options struct {
|
||||||
Hostname string
|
Hostname string
|
||||||
Month string
|
Month string
|
||||||
Pidfile string
|
Pidfile string
|
||||||
|
Queue int
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -71,5 +72,6 @@ func init() {
|
||||||
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
||||||
flag.BoolVar(&opts.Bulk, "B", false, "Bulk")
|
flag.BoolVar(&opts.Bulk, "B", false, "Bulk")
|
||||||
flag.IntVar(&opts.MaxError, "E", 100, "Max Mongodb Error")
|
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")
|
flag.StringVar(&opts.Pidfile, "p", opts.Pidfile, "pid file")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue