Pass parameters directly instead of through a config struct
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
package mqtt
|
||||
|
||||
type Config struct {
|
||||
Host string `yaml:"host" envconfig:"MQTT_HOST"`
|
||||
Port string `yaml:"port" envconfig:"MQTT_PORT"`
|
||||
Username string `yaml:"username" envconfig:"MQTT_USERNAME"`
|
||||
Password string `yaml:"password" envconfig:"MQTT_PASSWORD"`
|
||||
ClientID string `yaml:"client_id" envconfig:"MQTT_CLIENT_ID"`
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ var defaultHandler paho.MessageHandler = func(client paho.Client, msg paho.Messa
|
||||
fmt.Printf("MSG: %s\n", msg.Payload())
|
||||
}
|
||||
|
||||
func New(config Config) paho.Client {
|
||||
opts := paho.NewClientOptions().AddBroker(fmt.Sprintf("%s:%s", config.Host, config.Port))
|
||||
opts.SetClientID(config.ClientID)
|
||||
func New(host string, port int, clientID string, username string, password string) paho.Client {
|
||||
opts := paho.NewClientOptions().AddBroker(fmt.Sprintf("%s:%d", host, port))
|
||||
opts.SetClientID(clientID)
|
||||
opts.SetDefaultPublishHandler(defaultHandler)
|
||||
opts.SetUsername(config.Username)
|
||||
opts.SetPassword(config.Password)
|
||||
opts.SetUsername(username)
|
||||
opts.SetPassword(password)
|
||||
opts.SetOrderMatters(false)
|
||||
|
||||
client := paho.NewClient(opts)
|
||||
|
||||
Reference in New Issue
Block a user