Write data in database table
This commit is contained in:
39
config/config.go
Normal file
39
config/config.go
Normal file
@@ -0,0 +1,39 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user