mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
/**
|
|
* Copyright (c) Mainflux
|
|
*
|
|
* Mainflux server is licensed under an Apache license, version 2.0.
|
|
* All rights not explicitly granted in the Apache license, version 2.0 are reserved.
|
|
* See the included LICENSE file for more details.
|
|
*/
|
|
|
|
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/BurntSushi/toml"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
// HTTP
|
|
HttpHost string
|
|
HttpPort int
|
|
|
|
// Mongo
|
|
MongoHost string
|
|
MongoPort int
|
|
MongoDatabase string
|
|
|
|
// MQTT
|
|
MqttHost string
|
|
MqttPort int
|
|
|
|
// Influx
|
|
InfluxHost string
|
|
InfluxPort int
|
|
InfluxDatabase string
|
|
}
|
|
|
|
func (cfg *Config) Parse() {
|
|
|
|
var confFile string
|
|
|
|
testEnv := os.Getenv("TEST_ENV")
|
|
if testEnv == "" && len(os.Args) > 1 {
|
|
// We are not in the TEST_ENV (where different args are provided)
|
|
// and provided config file as an argument
|
|
confFile = os.Args[1]
|
|
} else {
|
|
// default cfg path to source dir, as we keep cfg.yml there
|
|
confFile = os.Getenv("GOPATH") + "/src/github.com/mainflux/mainflux/config/config.toml"
|
|
}
|
|
|
|
if _, err := toml.DecodeFile(confFile, &cfg); err != nil {
|
|
// handle error
|
|
fmt.Println("Error parsing Toml")
|
|
}
|
|
}
|