2015-11-20 15:23:12 +01:00
|
|
|
// options
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
RedisTTL time.Duration
|
|
|
|
CurrentPath string
|
|
|
|
Exe string
|
|
|
|
LogFile string
|
2015-11-20 16:17:31 +01:00
|
|
|
Timeout time.Duration
|
2015-11-20 15:23:12 +01:00
|
|
|
Debug bool
|
|
|
|
Version bool
|
2015-11-20 16:17:31 +01:00
|
|
|
Concurrent int
|
2015-11-24 12:28:22 +01:00
|
|
|
MaxError int
|
2015-11-20 15:23:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func usage() {
|
2015-11-24 12:28:22 +01:00
|
|
|
fmt.Println("Usage: llmongo -m <mongo uri> -r <redis uri> -t <redis keys ttl> -l <logfile> -b <concurrent thread> -T <running ttl> -v\n")
|
2015-11-20 15:23:12 +01:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var err error
|
|
|
|
opts.CurrentPath, err = filepath.Abs(filepath.Dir(os.Args[0]))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
opts.LogFile = path.Join(opts.CurrentPath, opts.LogFile)
|
|
|
|
pid.PIDFile = path.Join(opts.CurrentPath, "run", path.Base(os.Args[0])+".pid")
|
|
|
|
opts.Exe = path.Base(os.Args[0])
|
|
|
|
|
|
|
|
flag.StringVar(&dbs.MongoUri, "m", dbs.MongoUri, "Mongodb")
|
|
|
|
flag.StringVar(&dbs.RedisUri, "r", dbs.RedisUri, "Redis")
|
|
|
|
flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename")
|
2015-11-20 16:17:31 +01:00
|
|
|
flag.DurationVar(&opts.RedisTTL, "t", opts.RedisTTL, "Redis keys TTL")
|
2015-11-20 15:23:12 +01:00
|
|
|
flag.BoolVar(&opts.Version, "v", false, "Version")
|
2015-11-20 16:31:39 +01:00
|
|
|
flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")
|
2015-11-20 15:23:12 +01:00
|
|
|
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
2015-11-20 16:17:31 +01:00
|
|
|
flag.IntVar(&opts.Concurrent, "c", 1, "Concurrent thread")
|
2015-11-24 12:28:22 +01:00
|
|
|
flag.IntVar(&opts.MaxError, "E", 100, "Max Mongodb Error")
|
2015-11-20 15:23:12 +01:00
|
|
|
}
|