gestisce cluster di mongodb

aggiunte le funzioni di hash con SHA1 e MD5 (default)
This commit is contained in:
Michele 2017-06-09 16:08:32 +02:00
parent 6896b447c5
commit 7a52478c63
6 changed files with 29 additions and 9 deletions

View file

@ -3,6 +3,6 @@ FROM scratch
MAINTAINER Michele Fadda "<mikif70@gmail.com>"
COPY lastlogin_mongodb-v4.2.0 /bin/lastlogin_mongodb
COPY lastlogin_mongodb-v4.3.0 /bin/lastlogin_mongodb
ENTRYPOINT [ "/bin/lastlogin_mongodb" ]

3
Docker/build.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t mikif70/llmongo:4.3.0 .

View file

@ -6,9 +6,8 @@ docker run \
--name llmongo_tiscali \
--log-opt max-size=2m \
--log-opt max-file=5 \
mikif70/llmongo:4.2.0 \
mikif70/llmongo:4.2.1 \
-l /data/llmongo.log \
-p /data/llmongo.pid \
-r redis-ll.mail.tiscali.sys:6379 \
-m 10.39.80.189:27017 \
-d lastlogin \

View file

@ -2,6 +2,8 @@
package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"fmt"
@ -19,7 +21,7 @@ type consumed struct {
logins []string
}
func hash(val []byte) string {
func hash256(val []byte) string {
h := sha256.New()
h.Write(val)
@ -27,6 +29,22 @@ func hash(val []byte) string {
return hex.EncodeToString(h.Sum(nil))
}
func hash160(val []byte) string {
h := sha1.New()
h.Write(val)
return hex.EncodeToString(h.Sum(nil))
}
func hash128(val []byte) string {
h := md5.New()
h.Write(val)
return hex.EncodeToString(h.Sum(nil))
}
// protocol:timestamp:ip:country
func consumer() {
@ -68,7 +86,7 @@ func consumer() {
}
// genera l' _ID con user + timestamp + ip
mlID := hash([]byte(fmt.Sprintf("%s%s%s", prod.user, time.Unix(date, 0).Format("20060102T15"), sval[2]))) // Format("20060102T150405")
mlID := hash160([]byte(fmt.Sprintf("%s%s%s", prod.user, time.Unix(date, 0).Format("20060102T15"), sval[2]))) // Format("20060102T150405")
ml := MongoLogin{
ID: mlID,
User: prod.user,

2
dbs.go
View file

@ -90,7 +90,7 @@ func (db *Dbs) poolRedis() {
func (db *Dbs) connectMongo() {
mongoList := strings.Split(db.MongoURI, ",")
mongoList := strings.Split(db.MongoURI, "|")
for m := range mongoList {
nm, err := mgo.Dial(fmt.Sprintf("mongodb://%s", mongoList[m]))

View file

@ -12,7 +12,7 @@ import (
)
const (
_Version = "v4.2.0"
_Version = "v4.3.0"
_Producer = 0
_Consumer = 1
_Remover = 2
@ -75,8 +75,8 @@ func main() {
// defer pid.Remove()
start := time.Now()
fmt.Printf("Start: %+v\n", opts)
log.Printf("Start: %+v\n", opts)
fmt.Printf("Start:\t%+v\n\t%+v\n", opts, dbs)
log.Printf("Start:\t%+v\n\t%+v\n", opts, dbs)
opts.Month = start.Format("0601")