llmongodb/consul.go

45 lines
735 B
Go
Raw Permalink Normal View History

2018-11-22 12:29:08 +01:00
package main
import (
"fmt"
"log"
"time"
"github.com/hashicorp/consul/api"
)
2018-11-27 15:10:19 +01:00
// Consul client structure
2018-11-22 12:29:08 +01:00
type Consul struct {
RedisTTL time.Duration
Timeout time.Duration
MaxError int
Influxdb string
Month string
Retention float64
MongoURI string
Database string
RedisURI string
2018-11-27 15:10:19 +01:00
Client *api.Client
2018-11-22 12:29:08 +01:00
}
2018-11-27 15:10:19 +01:00
// NewClient New consul client
func NewClient() *Consul {
2018-11-22 12:29:08 +01:00
client, err := api.NewClient(api.DefaultConfig())
if err != nil {
2018-11-27 15:10:19 +01:00
log.Fatalf("Consul error: %+v\n", err)
if opts.Debug {
fmt.Printf("Consul error: %+v\n", err)
}
2018-11-22 12:29:08 +01:00
}
2018-11-27 15:10:19 +01:00
consul := &Consul{
Client: client,
RedisTTL: opts.RedisTTL,
Timeout: opts.Timeout,
MaxError: opts.MaxError,
Influxdb: opts.Influxdb,
}
return consul
2018-11-22 12:29:08 +01:00
}