implementata l'opzione DEBUG

forzata l'ora in UTC
This commit is contained in:
Miki 2016-01-13 17:15:01 +01:00
parent cecc92066d
commit 4bf4821015
2 changed files with 15 additions and 9 deletions

11
main.go
View file

@ -4,7 +4,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"gopkg.in/mgo.v2"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
@ -12,6 +11,8 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"time" "time"
"gopkg.in/mgo.v2"
) )
type Options struct { type Options struct {
@ -23,6 +24,7 @@ type Options struct {
TimeStart time.Time TimeStart time.Time
DateStop time.Duration DateStop time.Duration
Version bool Version bool
Debug bool
} }
const ( const (
@ -38,7 +40,7 @@ var (
opts = Options{ opts = Options{
MongoUri: "mongodb://127.0.0.1:27018", MongoUri: "mongodb://127.0.0.1:27018",
LogFile: "log/imp.log", LogFile: "log/imp.log",
DateStart: time.Now().Add(-time.Hour).Format(_tformat), DateStart: time.Now().UTC().Add(-time.Hour).Format(_tformat),
DateStop: time.Hour, DateStop: time.Hour,
} }
mimp = MongoImp{} mimp = MongoImp{}
@ -55,7 +57,7 @@ func connectMongo() {
} }
func usage() { func usage() {
fmt.Println("Usage: imp_mongo -d <date (yyyy-mm-dd:hh)> -r <date range (HHh)> -m <mongodb uri> -l <logfile> -v\n") fmt.Println("Usage: imp_mongo -d <date (yyyy-mm-dd:hh)> -r <date range (HHh)> -m <mongodb uri> -l <logfile> -v -D\n")
os.Exit(0) os.Exit(0)
} }
@ -71,6 +73,7 @@ func init() {
flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename") flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename")
flag.StringVar(&opts.DateStart, "d", opts.DateStart, "From Date <YYYY-MM-DD:HH>") flag.StringVar(&opts.DateStart, "d", opts.DateStart, "From Date <YYYY-MM-DD:HH>")
flag.DurationVar(&opts.DateStop, "r", opts.DateStop, "Duration <HH>h") flag.DurationVar(&opts.DateStop, "r", opts.DateStop, "Duration <HH>h")
flag.BoolVar(&opts.Debug, "D", false, "Debug")
flag.BoolVar(&opts.Version, "v", false, "Version") flag.BoolVar(&opts.Version, "v", false, "Version")
} }
@ -141,8 +144,6 @@ func main() {
} }
} }
// fmt.Printf("%+v\n", mimp)
fmt.Printf("Stop: %v\n", time.Since(start)) fmt.Printf("Stop: %v\n", time.Since(start))
log.Printf("Stop: %v\n", time.Since(start)) log.Printf("Stop: %v\n", time.Since(start))
} }

View file

@ -2,7 +2,7 @@
package main package main
import ( import (
// "fmt" "fmt"
"log" "log"
"strconv" "strconv"
"strings" "strings"
@ -113,9 +113,11 @@ func parse(body string, stime time.Time) {
index.Date = stime index.Date = stime
} else if strings.HasPrefix(lines[ind], "counters") { } else if strings.HasPrefix(lines[ind], "counters") {
k := strings.Split(lines[ind], ";") k := strings.Split(lines[ind], ";")
// fmt.Printf("%s = %s\n", k[0], k[1])
key := strings.Split(k[0], "/") key := strings.Split(k[0], "/")
// fmt.Printf("Keys: %s - %s - %s\n", key[0], key[1], key[2]) if opts.Debug {
// fmt.Printf("%s = %s\n", k[0], k[1])
// fmt.Printf("Keys: %s - %s - %s\n", key[0], key[1], key[2])
}
if key[0] == "counters" { if key[0] == "counters" {
switch key[1] { switch key[1] {
case "banner": case "banner":
@ -201,5 +203,8 @@ func parse(body string, stime time.Time) {
if err != nil { if err != nil {
log.Println("Insert Errro: ", err) log.Println("Insert Errro: ", err)
} }
// fmt.Printf("%+v\n", info)
if opts.Debug {
fmt.Printf("%+v\n", mimp)
}
} }