in go/mqtt/connect.go [317:376]
func (c *SessionClient) buildConnectPacket(
ctx context.Context,
reconnect bool,
) (*paho.Connect, error) {
packet := &paho.Connect{
ClientID: c.clientID,
CleanStart: !reconnect && c.options.CleanStart,
KeepAlive: c.options.KeepAlive,
Properties: &paho.ConnectProperties{
SessionExpiryInterval: &c.options.SessionExpiry,
ReceiveMaximum: &c.options.ReceiveMaximum,
RequestProblemInfo: true,
User: internal.MapToUserProperties(
c.options.ConnectUserProperties,
),
},
}
if c.options.Username != nil {
username, usernameFlag, err := c.options.Username(ctx)
if err != nil {
return nil, &InvalidArgumentError{
message: "error getting username",
wrapped: err,
}
}
if usernameFlag {
packet.UsernameFlag = true
packet.Username = username
}
}
if c.options.Password != nil {
password, passwordFlag, err := c.options.Password(ctx)
if err != nil {
return nil, &InvalidArgumentError{
message: "error getting password",
wrapped: err,
}
}
if passwordFlag {
packet.PasswordFlag = true
packet.Password = password
}
}
if c.options.Auth != nil {
authValues, err := c.options.Auth.InitiateAuth(false)
if err != nil {
return nil, &InvalidArgumentError{
message: "error getting auth values",
wrapped: err,
}
}
packet.Properties.AuthData = authValues.AuthData
packet.Properties.AuthMethod = authValues.AuthMethod
}
return packet, nil
}