diff --git a/consul.go b/consul.go index 6c2c3d0..a959a24 100644 --- a/consul.go +++ b/consul.go @@ -3,13 +3,12 @@ package main import ( "fmt" "log" - "strconv" - "strings" "time" "github.com/hashicorp/consul/api" ) +// Consul client structure type Consul struct { RedisTTL time.Duration Timeout time.Duration @@ -20,11 +19,26 @@ type Consul struct { MongoURI string Database string RedisURI string + Client *api.Client } -func getClient() { +// NewClient New consul client +func NewClient() *Consul { client, err := api.NewClient(api.DefaultConfig()) if err != nil { - panic(err) + log.Fatalf("Consul error: %+v\n", err) + if opts.Debug { + fmt.Printf("Consul error: %+v\n", err) + } } + + consul := &Consul{ + Client: client, + RedisTTL: opts.RedisTTL, + Timeout: opts.Timeout, + MaxError: opts.MaxError, + Influxdb: opts.Influxdb, + } + + return consul } diff --git a/counter.go b/counter.go index f9505d2..1b616a0 100644 --- a/counter.go +++ b/counter.go @@ -6,6 +6,7 @@ import ( "time" ) +// Counterchan counter structure type Counterchan struct { tipo string val int @@ -38,6 +39,7 @@ func NewCounter() *Counter { } } +// Run open channel to receive counter func (c *Counter) Run() { for { tocount := <-counter diff --git a/options.go b/options.go index 32c33d3..96ab622 100644 --- a/options.go +++ b/options.go @@ -28,6 +28,7 @@ type Options struct { Queue int Retention float64 Consul string + Port int } var ( @@ -47,6 +48,7 @@ func usage() { -T -i -C + -P [port] ## used by consul to check services ## -q -R -v @@ -72,6 +74,7 @@ func init() { flag.StringVar(&dbs.RedisURI, "r", "", "Redis") flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename") flag.StringVar(&opts.Consul, "C", opts.Consul, "consul client") + flag.IntVar(&opts.Port, "P", 10500, "service check port") flag.DurationVar(&opts.RedisTTL, "t", opts.RedisTTL, "Redis keys TTL") flag.BoolVar(&opts.Version, "v", false, "Version") flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")