30 lines
554 B
Go
30 lines
554 B
Go
package mqtt
|
|
|
|
import mqttClient "github.com/eclipse/paho.mqtt.golang"
|
|
|
|
type Session struct {
|
|
ClientId string
|
|
Username []byte
|
|
Password []byte
|
|
Client *mqttClient.Client
|
|
}
|
|
|
|
var Sessions map[string]*Session = make(map[string]*Session)
|
|
|
|
func CreateSession(mqttId string, user, passwd []byte) *Session {
|
|
Sessions[mqttId] = &Session{
|
|
ClientId: mqttId,
|
|
Username: user,
|
|
Password: passwd,
|
|
}
|
|
return Sessions[mqttId]
|
|
}
|
|
|
|
func GetSession(mqttId string) *Session {
|
|
return Sessions[mqttId]
|
|
}
|
|
|
|
func DelSession(mqttId string) {
|
|
delete(Sessions, mqttId)
|
|
}
|