This commit is contained in:
Michele Fadda 2018-11-27 15:10:19 +01:00
parent 5bc0076ecf
commit a2fc00df74
3 changed files with 23 additions and 4 deletions

View file

@ -3,13 +3,12 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"strconv"
"strings"
"time" "time"
"github.com/hashicorp/consul/api" "github.com/hashicorp/consul/api"
) )
// Consul client structure
type Consul struct { type Consul struct {
RedisTTL time.Duration RedisTTL time.Duration
Timeout time.Duration Timeout time.Duration
@ -20,11 +19,26 @@ type Consul struct {
MongoURI string MongoURI string
Database string Database string
RedisURI string RedisURI string
Client *api.Client
} }
func getClient() { // NewClient New consul client
func NewClient() *Consul {
client, err := api.NewClient(api.DefaultConfig()) client, err := api.NewClient(api.DefaultConfig())
if err != nil { 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
}

View file

@ -6,6 +6,7 @@ import (
"time" "time"
) )
// Counterchan counter structure
type Counterchan struct { type Counterchan struct {
tipo string tipo string
val int val int
@ -38,6 +39,7 @@ func NewCounter() *Counter {
} }
} }
// Run open channel to receive counter
func (c *Counter) Run() { func (c *Counter) Run() {
for { for {
tocount := <-counter tocount := <-counter

View file

@ -28,6 +28,7 @@ type Options struct {
Queue int Queue int
Retention float64 Retention float64
Consul string Consul string
Port int
} }
var ( var (
@ -47,6 +48,7 @@ func usage() {
-T <running timeout> -T <running timeout>
-i <influxdb [localname@ip:port]> -i <influxdb [localname@ip:port]>
-C <consul [ip:port]> -C <consul [ip:port]>
-P <check port> [port] ## used by consul to check services ##
-q <parallel consumer> -q <parallel consumer>
-R <retention> -R <retention>
-v <version> -v <version>
@ -72,6 +74,7 @@ func init() {
flag.StringVar(&dbs.RedisURI, "r", "", "Redis") flag.StringVar(&dbs.RedisURI, "r", "", "Redis")
flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename") flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename")
flag.StringVar(&opts.Consul, "C", opts.Consul, "consul client") 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.DurationVar(&opts.RedisTTL, "t", opts.RedisTTL, "Redis keys TTL")
flag.BoolVar(&opts.Version, "v", false, "Version") flag.BoolVar(&opts.Version, "v", false, "Version")
flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout") flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")