40 lines
958 B
Go
40 lines
958 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
//"fmt"
|
||
|
"log"
|
||
|
|
||
|
"github.com/pelletier/go-toml"
|
||
|
)
|
||
|
|
||
|
type Config struct {
|
||
|
BrokerAddress string
|
||
|
BrokerPort int64
|
||
|
BrokerClientID string
|
||
|
BrokerUsername string
|
||
|
BrokerPassword string
|
||
|
EnableTLS bool
|
||
|
}
|
||
|
|
||
|
func NewConfig(configFilename string) (*Config, error) {
|
||
|
tomlData, err := toml.LoadFile(configFilename)
|
||
|
|
||
|
conf := Config{"", 8883, "go_client", "", "", true}
|
||
|
|
||
|
if err != nil {
|
||
|
//fmt.Println("Error ", err.Error())
|
||
|
log.Printf("ERROR: NewConfig(): %s", err.Error())
|
||
|
return nil, err
|
||
|
} else {
|
||
|
// retrieve data directly
|
||
|
conf.BrokerAddress = tomlData.Get("BROKER.Address").(string)
|
||
|
conf.BrokerPort = tomlData.Get("BROKER.Port").(int64)
|
||
|
conf.BrokerClientID = tomlData.Get("BROKER.ClientId").(string)
|
||
|
conf.BrokerUsername = tomlData.Get("BROKER.Username").(string)
|
||
|
conf.BrokerPassword = tomlData.Get("BROKER.Password").(string)
|
||
|
conf.EnableTLS = tomlData.Get("BROKER.EnableTLS").(bool)
|
||
|
}
|
||
|
|
||
|
return &conf, nil
|
||
|
}
|