Skip to content

Commit

Permalink
Added configuration of user and password for influxdb
Browse files Browse the repository at this point in the history
  • Loading branch information
pawski committed May 28, 2020
1 parent ab5c42e commit d161028
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config.yml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
influx_host: https://influxdb.host
influx_host: https://localhost:8086
influx_database: xchange
rabbitmq_url: amqp://guest:guest@localhost:5672
collect_update_interval: 10 # In seconds
Expand Down
16 changes: 7 additions & 9 deletions configuration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

type config struct {
InfluxDbHost string `yaml:"influx_host"`
InfluxDbUser string `yaml:"influx_user"`
InfluxDbPassword string `yaml:"influx_password"`
InfluxDbDatabase string `yaml:"influx_database"`
RabbitMqUrl string `yaml:"rabbitmq_url"`
WalutomatUrl string `yaml:"walutomat_url"`
Expand All @@ -17,31 +19,27 @@ type config struct {
WalutomatApiHost string `yaml:"walutomat_api_host"`
}

var cfg config
var cfg *config
var once sync.Once

func Get() config {
func Get() *config {
once.Do(func() {
cfg = loadConfiguration()
loadConfiguration()
})

return cfg
}

func loadConfiguration() config {
func loadConfiguration() {
source, err := ioutil.ReadFile("config.yml")

if err != nil {
logger.Get().Fatalf("error: %v", err)
}

var config config

err = yaml.Unmarshal([]byte(source), &config)
err = yaml.Unmarshal(source, &cfg)

if err != nil {
panic(err)
}

return config
}
6 changes: 3 additions & 3 deletions influxdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
var dbClient client.Client
var once sync.Once

func Get() (client.Client) {
func Get() client.Client {
once.Do(func(){
// Create a new HTTPClient
var err error
dbClient, err = client.NewHTTPClient(client.HTTPConfig{
Addr: configuration.Get().InfluxDbHost,
Username: "",
Password: "",
Username: configuration.Get().InfluxDbUser,
Password: configuration.Get().InfluxDbPassword,
})

if err != nil {
Expand Down

0 comments on commit d161028

Please sign in to comment.