diff --git a/consumer.go b/consumer.go index 3ade377..3e6d71a 100644 --- a/consumer.go +++ b/consumer.go @@ -27,6 +27,8 @@ func hash(val []byte) string { return hex.EncodeToString(h.Sum(nil)) } +// protocol:timestamp:ip:country + func consumer() { for { @@ -59,6 +61,12 @@ func consumer() { log.Printf("Date Error: %+v - %s - %s\n", err, prod.user, login) continue } + + // verifica se esiste la country + if len(sval) <= 3 { + sval = append(sval, "NONE") + } + // 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") ml := MongoLogin{ @@ -68,6 +76,7 @@ func consumer() { IP: sval[2], Date: time.Unix(date, 0), Insert: time.Now(), + Country: sval[3], } allLogins[mlID] = ml diff --git a/dbs.go b/dbs.go index ebaf976..ae25787 100644 --- a/dbs.go +++ b/dbs.go @@ -37,6 +37,7 @@ type MongoLogin struct { IP string `json:"ip" bson:"ip" gorethink:"ip"` Date time.Time `json:"date" bson:"date" gorethink:"date"` Insert time.Time `json:"insert" bson:"insert" gorethink:"insert"` + Country string `json:"country" bson:"country" gorethink:"country"` } // Ips structure diff --git a/main.go b/main.go index f9436ef..519ab0a 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( ) const ( - _Version = "v4.0.4" + _Version = "v4.1.0" _Producer = 0 _Consumer = 1 _Remover = 2